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

RE: Counting preceding nodes

Subject: RE: Counting preceding nodes
From: "Kevin Bird \(Matrix\)" <kevin.bird@xxxxxxxxxxxxxxxxxxxxxxx>
Date: Fri, 7 Jan 2005 16:44:41 -0000
xslt how to count progress
Thank you for the comprehensive answer.

Kevin 

> -----Original Message-----
> From: Michael Kay [mailto:mike@xxxxxxxxxxxx] 
> Sent: 07 January 2005 16:35
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject: RE:  Counting preceding nodes
> 
> It's easiest to do this in XSLT:
> 
>    <xsl:number count="level3" level="any" from="level1"/>
> 
> and of course you can put that in a variable.
> 
> In XPath 2.0 you can do 
> 
>    count(ancestor::level1/level2/level3[. << current()])
> 
> An XPath 1.0 solution, given that your hierarchy is very rigid, is
> 
>    count(preceding-sibling::level3) +
> count(../preceding-sibling::level2/level3)
> 
> If a level2 only ever has exactly one level3 child, as in 
> your example, you can just do
> 
>    count(../preceding-sibling::*)
> 
> Michael Kay
> http://www.saxonica.com/  
> 
> 
> > -----Original Message-----
> > From: Kevin Bird [mailto:kevin.bird@xxxxxxxxxxxxxxxxxxxxxxx]
> > Sent: 07 January 2005 16:20
> > To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> > Subject:  Counting preceding nodes
> > 
> > Hi
> > 
> > I have the following XML structure, <level3/> is my context node. I 
> > want to count the preceding <level3/> nodes that have the same 
> > <level1> grandparent. I can't seem to get my head around the XPATH 
> > syntax.
> > 
> > <wrapper>
> > <level1>
> > 	<level2>
> > 		<level3/>
> > 	</level2>
> > 	<level2>
> > 		<level3/>
> > 	</level2>
> > 	<level2>
> > 		<level3/>
> > 	</level2>
> > </level1>
> > <level1>
> > 	<level2>
> > 		<level3/>
> > 	</level2>
> > 	<level2>
> > 		<level3/>
> > 	</level2>
> > 	<level2>
> > 		<level3/>	<!-- when context, preceding count will
> > be 2 -->
> > 	</level2>
> > 	<level2>
> > 		<level3/>	<!-- when context, preceding count will
> > be 3 -->
> > 	</level2>
> > </level1>
> > </wrapper>
> > 
> > Thanks.
> >  
> > --
> > Kevin

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.