[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: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx>
Date: Wed, 5 Nov 2003 10:00:10 +0000
find parents
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


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.