Altova Mailing List Archives>Archive Index >comp.text.xml Archive Home >Recent entries >Thread Prev - xslt / xpath question [Thread Next] Re: xslt / xpath questionTo: NULL Date: 8/5/2004 10:19:00 AM Brian Schroeder <spam0504@b...> writes: > I've got the following situation: > > === a.xml === > <?xml version="1.0" encoding="ISO-8859-1"?> > <n categorie="A"> > <n categorie="B"> > <n categorie="C"/> > </n> > <n categorie="D"/> > </n> > === > > I want to transform this via xslt to the following > > A > A->B > A->B->C > A->D Further to your other replies, rather than use the ancestor axis this kind of thing is generally done more naturally in XSLT with recursion. This stylesheet (I know it doesn't look more elegant at first sight, but recursion is much nicer, honestly) produces the output you desire: <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="text"/> <xsl:template match="/"> <xsl:apply-templates select="n"/> </xsl:template> <xsl:template match="n"> <xsl:param name="prefix"/> <!-- update the prefix --> <xsl:variable name="current"> <xsl:choose> <xsl:when test="$prefix"> <xsl:value-of select="concat($prefix,'->',@categorie)"/> </xsl:when> <xsl:otherwise> <xsl:value-of select="@categorie"/> </xsl:otherwise> </xsl:choose> </xsl:variable> <!-- output the new prefix --> <xsl:value-of disable-output-escaping="yes" select="$current"/> <xsl:text>
</xsl:text> <!-- a newline --> <!-- recursively treat my child-nodes --> <xsl:apply-templates select="n"> <xsl:with-param name="prefix"> <xsl:value-of select="$current"/> </xsl:with-param> </xsl:apply-templates> </xsl:template> </xsl:stylesheet> -- Ben Edgington Mail to the address above is discarded. Mail to ben at that address might be read. http://www.edginet.org/ | ||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
