[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: creating XML hierarchy where not existed before??

Subject: RE: creating XML hierarchy where not existed before??
From: "Meltsner, Kenneth" <Kenneth.Meltsner@xxxxxx>
Date: Mon, 18 Dec 2000 14:39:21 -0500
last names starts with wh
One minor mistake with my pseudo-code:

If you're trying to build a hierarchy of multiple layers, you need to move the call-template to the next element of the appropriate level if (and only if) there isn't an element of higher level between the current element and that next element.  That is, if you're looking for group2 elements, you can jump to the next group2 element on the forward-sibling access iff there isn't an intervening group1.

The other way to do this is with keys: for each element, define a key that points to its immediate "parent" -- the element of one level higher right before it.  Then for each element, process the element followed by processing all the elements that have that element as a parent.

<xsl:key name="actparent" match="//p[starts-with(@stylename, 'Level2')]" use="preceding-sibling::p[starts-with(@stylename,'Level1')][1]" /> 
  <xsl:key name="actparent" match="//p[starts-with(@stylename, 'Level3')]" use="preceding-sibling::p[starts-with(@stylename,'Level2')][1]" /> 
  <xsl:key name="actparent" match="//p[starts-with(@stylename, 'Level4')]" use="preceding-sibling::p[starts-with(@stylename,'Level3')][1]" /> 
  <xsl:key name="actparent" match="//p[starts-with(@stylename, 'Level5')]" use="preceding-sibling::p[starts-with(@stylename,'Level4')][1]" /> 
  <xsl:key name="actparent" match="//p[starts-with(@stylename, 'Level6')]" use="preceding-sibling::p[starts-with(@stylename,'Level5')][1]" /> 
  
and from a template elsewhere in the stylesheet (that starts with "group1" element"):

<xsl:for-each select="key('actparent', .)">
  <xsl:apply-templates select="." /> 
  </xsl:for-each>
  
to build a hierarchy of activities (actparent == activity parent) that's 6 levels deep.

Ken

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.