xsl-list
[Top] [All Lists]

RE: [xsl] Xpath to count occurances within a single parent

2006-08-28 13:09:26
Thanks Mike,

Dave's mention of xsl:number also helped allot! I think this is the final
solutions for the situation I have

Thanks again to everyone for the help!

David White

This gives me a variable that tells me how many cautions are preceding

-----Original Message-----
From: Michael Kay [mailto:mike(_at_)saxonica(_dot_)com] 
Sent: Monday, August 28, 2006 2:54 PM
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: RE: [xsl] Xpath to count occurances within a single parent

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(_at_)kencook(_dot_)com]
Sent: 28 August 2006 17:07
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: [xsl] 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



--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: 
<mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--



--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--



--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

<Prev in Thread] Current Thread [Next in Thread>
  • RE: [xsl] Xpath to count occurances within a single parent, David White <=