This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: Proper syntax for counting all prior nodes in XPath?
- To: xsl-list at lists dot mulberrytech dot com
- Subject: Re: [xsl] Proper syntax for counting all prior nodes in XPath?
- From: Johannes Döbler <jd at aztecrider dot com>
- Date: Mon, 11 Jun 2001 19:49:08 +0200
- Reply-To: xsl-list at lists dot mulberrytech dot com
Try the XPath expression 'count(preceding::* | ancestor::*)' to count all
the element nodes prior to the context node.
Johannes
At 11:16 11.06.01 -0600, you wrote:
>Hi,
>
>With an XML document like this:
><DOC>
> <CHAPTER>
> <SECTION>
> <PAGE>
> <LINE>Test</LINE>
> <LINE>Test 2</LINE>
> </PAGE>
> </SECTION>
> <SECTION>
> <PAGE>
> <LINE>Test 3</LINE>
> </PAGE>
> </SECTION>
> </CHAPTER>
></DOC>
>
>How can my XSL count all the preceding nodes? For example, when my template
>is processing the <LINE>Test 3</LINE>, I want to count all nodes before it,
>which would be 2 <LINE>s, 2 <PAGE>s, 2 <SECTION>s, 1 <CHAPTER>, and 1 <DOC>.
>Does this make sense?
>
>It would be something like <xsl:number level="any"
>count="DOC|CHAPTER|SECTION|PAGE|LINE"/>, except I want to use the count in
>an <xsl:if />, not just display it. I have tried using <xsl:if
>test="count(something)">, but I do not know what the proper "something" is.
>Any suggestions?
>
>Thanks
>Jason
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list