[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] RE: creating XML hierarchy where not existed before??
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
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|