[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] traversing up nodes until a certain attribute, then ba
Hello, Here is sample XML <root> <zero> <one id="a"> <two> <three id="c"> <four id="d"> <five> <six> <seven/> </six> </five> </four> </three> </two> </one> </zero> </root> which I want to transform into this: root zero a a two c d d five d five six d five six seven just giving the element name if no ancestor has the attribute "id" and giving the closest ancestor "id" as the starting point and all element names back to the current node if it does have an ancestor with attribute "id". Here is what I have so far, but it's not enough. <?xml version="1.0" encoding="utf-8" standalone="yes"?> <xsl:transform version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="text" version="1.0" encoding="utf-8" omit-xml-declaration="yes" standalone="no" indent="no" media-type="text/plain"/> <xsl:template match="*"> <xsl:choose> <xsl:when test="ancestor-or-self::*[@id]"> <xsl:for-each select="ancestor-or-self::*[@id]"> <xsl:if test="position() = last()"> <xsl:value-of select="@id"/> </xsl:if> </xsl:for-each> </xsl:when> <xsl:otherwise> <xsl:value-of select="name(.)"/> </xsl:otherwise> </xsl:choose> <xsl:apply-templates/> </xsl:template> </xsl:transform> That results in: root zero a a c d d d d but I need to process back until the current node (not beyond it...) giving all element names along the way, starting after the closest ancestor node with an attribute "id". I've done some searching and I might need to do some XSLT grouping, but I'm not sure yet. Can anyone help? ____________________________________________________________________________________ No need to miss a message. Get email on-the-go with Yahoo! Mail for Mobile. Get started. http://mobile.yahoo.com/mail
|
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
|