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

RE: Xpath to count occurances within a single parent

Subject: RE: Xpath to count occurances within a single parent
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Mon, 28 Aug 2006 20:53:46 +0100
xpath 1.0 intersect
In XPath 2.0,

count(preceding::caution intersect ancestor::chapter//caution)

In 1.0, you can simulate the intersect operator using the equivalence

A intersect B ==> A[count(.|B) = count(B)]

But you might be better off using 

<xsl:number count="caution" level="any" from="chapter"/>

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

 

> -----Original Message-----
> From: David White [mailto:davidw@xxxxxxxxxxx] 
> Sent: 28 August 2006 17:07
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject:  Xpath to count occurances within a single parent
> 
> Hello all,
> 
> I have the following XML structure
> 
> <book>
> <chapter>
> <caution/>
> <caution/>
> <caution/>
> </chapter>
> 
> <chapter>
> <sect1>
> <caution/>
> </sect1>
> <caution/>
> <caution/>
> </chapter>
> </book>
> 
> What I need is an XPATH statement that counts the number of 
> preceding cautions in each chapter.  From any given chapter element.
> 
> EXAMPLE:
> count(preceding::caution)!= 0
> 
> This XPATH works correctly for the first <chapter> but fails 
> on the second <chapter> because one <caution> is a child of <sect1>.
> 
> Is there a way to count preceding <cautions> within a 
> <chapter> element despite nesting?
> 
> Thanks,
> 
> David White

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.