[XSL-LIST Mailing List Archive Home]
[By Thread]
[By Date]
[Recent Entries]
[Reply To This Message]
Re: recursive call of template - how to find parents
Subject: Re: recursive call of template - how to find parents
From: Michael Olszynski <m.olszynski@xxxxxxxxxxxxx>
Date: Wed, 05 Nov 2003 13:51:34 +0100
|
Hi Jeni,
that was such a good idea, I wasn´t familiar with iteratring along axes.
That´s really great. One thing happens. If I use your topic template,
everything is working fine, except that the top most elements of the
sitemap don´t get a href. (in the html-file)
It is that way, because I still used my old sitemap template, which you
recommended to replace with the sitemap template you wrote. So I did
replace also the sitemap template. And now, I get a stack overflow
error, when I try to generate the homepage.
You wrote that I should come up with a more targetted path. Do I have to
change anything therefore in my xml-file?
Thanks a lot!
I appreciate your help!!!!
Take care Michael
Jeni Tennison wrote:
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/
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
RSS 2.0 |
|
Atom 0.3 |
|
|