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

RE: The right way to count from inside a match templat

Subject: RE: The right way to count from inside a match template
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Wed, 9 Mar 2005 19:47:26 -0000
xsl match count
The simplest way is just <xsl:number/> with no attributes.

In most cases you can also use position() - but the value of position()
depends on how the template was invoked. If it was invoked by

<xsl:template match="root">
  <xsl:apply-templates select="a"/>
</xsl:template>

then position() will give you the answer you want; but if it was

<xsl:template match="b">
 <xsl:apply-templates select=".."/>
</xsl:template>

then it won't.

count(preceding-sibling::a)+1 should also work.

Michael Kay
http://www.saxonica.com/

> -----Original Message-----
> From: nutdev2002 [mailto:nutdev2002@xxxxxxxx]
> Sent: 09 March 2005 19:00
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject:  The right way to count from inside a match template
>
> Dear All,
>  I am sure this is a old chestnut of a question, but I just cannot get
> it to work.
>
> I have an xsl which is something like this:
>
> <root>
> <a><b>lots of stuff</b></a>
> <a><b>lots of stuff</b></a>
> <a><b>lots of stuff</b></a>
> <a><b>lots of stuff</b></a>
> <a><b>lots of stuff</b></a>
> <a><b>lots of stuff</b></a>
> <a><b>lots of stuff</b></a>
> </root>
>
> and I have a template
>
> <xsl:template match="a">
>
> <!--Show which element I on using-->
>
> <!--display lots of stuff-->
>
> </xsl:template>
>
> For the <!--Show which element I on using--> I am trying various
> different combinations
> of <xsl:number value="something">
>
> I have tried counting preceding siblings, position and several other
> things, and I only ever get
> a 1.
>
> I would be really grateful if you could tell me What is the
> right way to
> show 1,2,3,4,5 and then contents of each 'a4 element within the
> template.
>
> Thanks very much in advance,

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.