Subject: Re: [xsl] recursive call of template - how to find parents From: Michael Olszynski <m.olszynski@xxxxxxxxxxxxx> Date: Wed, 05 Nov 2003 13:51:34 +0100 |
Thanks a lot! I appreciate your help!!!!
Hi Michael,
But now I need to output another attribute with every element, and I
need to output this attribute also from all its parents. How can I
find out if there´s still a parent left? I give you an example of my
xml-File my xslt-code and the desired output.
You don't have to do this recursively unless you particularly want to. The easiest way to create the href attribute that you're after is to use an <xsl:for-each> loop over the ancestors of the current <topic> element (and the current <topic> element itself), as follows:
<xsl:template match="topic"> <li> <a> <xsl:attribute name="href"> <xsl:for-each select="ancestor-or-self::topic"> <xsl:value-of select="@filename" /> <xsl:if test="position() != last()">/</xsl:if> </xsl:for-each> </xsl:attribute> <xsl:value-of select="."/> </a> <xsl:if test="topic"> <ul> <xsl:apply-templates select="topic"/> </ul> </xsl:if> </li> </xsl:template>
Note that you're currently generating the <li> elements for the top-most <topic> elements in a separate place; it would be easiest if you could combine them, such that the sitemap template looked like:
<xsl:template name="sitemap"> <ul> <xsl:apply-templates select="//homepage/topic" /> </ul> </xsl:template>
(It would also be best, for efficiency, if you could come up with a more targetted path to the top-level <topic> elements than "//homepage/topic".)
Cheers,
Jeni
--- Jeni Tennison http://www.jenitennison.com/
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] recursive call of templat, Jeni Tennison | Thread | Re: [xsl] recursive call of templat, Jeni Tennison |
[xsl] grouping for-each, james walker | Date | Re: [xsl] recursive call of templat, Jeni Tennison |
Month |