Re: [xsl] Proper syntax for counting all prior nodes in XPath?

Subject: Re: [xsl] Proper syntax for counting all prior nodes in XPath?
From: Johannes Döbler <jd@xxxxxxxxxxxxxx>
Date: Mon, 11 Jun 2001 19:49:08 +0200
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


Current Thread