XPath select ancestor / decendant tree from element to element

~Bullet

New Member
I currently have an xml document which looks like this:\[code\]<site> <body> <group name="content"> <Categories> <item id="1" name="cat1"> <Children> <item id="2" name="cat2"> <Children> <item id="3" name="cat3"> <Children> <item id="4" name="cat4" /> </Children> </item> <item id="5" name="cat5"> <Children> <item id="6" name="cat6" /> <item id="7" name="cat7" /> <item id="8" name="cat8" /> </Children> </item> <item id="9" name="cat9" /> <item id="10" name="cat10" /> </Children> </item> </Children> </item> </Categories> </group> </body></site>\[/code\]If a user has selected a category with id=3:How can I [in my xsl stylesheet], select all the descendants from the root Categories element to the selected element, and iterate through them ? Maybe something like: \[code\]<xsl:for-each select="//Categories//*[@id=3 and ancestor::Categories[1]]"> . . ?\[/code\]Leaving me to then just:\[code\]<xsl:value-of select="@name" /> >\[/code\]Resulting in:\[code\]cat1 > cat2 > cat3 >\[/code\]Please let me know if further clarification is needed. Many thanks.
 
Back
Top