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

Re: problem with XPath count()

Subject: Re: problem with XPath count()
From: "Michael Kay mike@xxxxxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Wed, 1 Nov 2023 08:48:44 -0000
Re:  problem with XPath count()
> I want to count, for each element, the number of preceding <text>
> elements that satisfy one or both of the following two conditions: 1)
> the element is the first of the list or 2) its string value begins with
> "x". Here is an example, with the expected number of the count after the
> element:
>
>

Firstly, I suspect you want the preceding-sibling axis rather than the
preceding axis.

The position() function returns the position of a node within the sequence of
nodes being processed, not its position within an XML tree. If you use it
within a predicate, it's the position of the item being tested within the
sequence of things being tested, which in your case is the sequence of
preceding text elements, in reverse document order.

To test whether a node is the first element child of its parent, use

not(preceding-siblling::*)

Michael Kay
Saxonica

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.