xpath/xslt to determine index of context node relative to all nodes of same name?

Posted by Geoff on Stack Overflow See other posts from Stack Overflow or by Geoff
Published on 2010-03-26T22:39:34Z Indexed on 2010/03/26 22:43 UTC
Read the original article Hit count: 514

Filed under:
|
|
|

Given the schema below - with a "query" node as the context, is it possible with xpath/xslt to determine the index of that "query" node relative to all "query" nodes in the document (not position() relative to its immediate siblings).

TIA,

Geoff

<section>
    <name>About</name>
    <link>about</link>
    <questions>
        <question>
            <query>Question 1</query>
            <answer>Lorem ipsum dolor sit amet, consectetur adipiscing elit. In cursus, elit id lacinia semper, ligula nunc rhoncus ante, in euismod tortor nibh dictum tellus.</answer>
        </question>
    </questions>
</section>

<section>
    <name>Contact</name>
    <link>contact</link>
    <questions>
        <question>
            <query>Question 1</query>
            <answer>Lorem ipsum dolor sit amet, consectetur adipiscing elit. In cursus, elit id lacinia semper, ligula nunc rhoncus ante, in euismod tortor nibh dictum tellus.</answer>
        </question>
        <question>
            <query>Question 2</query>
            <answer>Lorem ipsum dolor sit amet, consectetur adipiscing elit. In cursus, elit id lacinia semper, ligula nunc rhoncus ante, in euismod tortor nibh dictum tellus.</answer>
        </question>
    </questions>
</section>

© Stack Overflow or respective owner

Related posts about xpath

Related posts about Xml