[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: outputting unknown amount of child elements

Subject: Re: outputting unknown amount of child elements
From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx>
Date: Mon, 9 Feb 2004 13:02:22 +0000
passing unknown parameter number
Hi David,

> I should have stressed that not only do I want to ouput all the
> elements using recursion but I also want, effectively to know how
> many ancestors they each have in order to structure the output so it
> makes clear the hierarchical structure of the data.

You can do that in two ways. You can count the number of ancestors of
the <item> element that you're on using:

  count(ancestor::item)

Alternatively, you can pass a parameter into the template, adding one
on each recursion, as in:

<xsl:template match="item">
  <xsl:param name="ancestors" select="0" />
  ...
  <xsl:apply-templates>
    <xsl:with-param name="ancestors" select="$ancestors + 1" />
  </xsl:apply-templates>
</xsl:template>

If you're dealing with very deep hierarchies, using a parameter will
probably be speedier.

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.