xsl-list
[Top] [All Lists]

Finding the following sibling of same type

2004-08-29 11:06:42
Hi,

    I have an XML document that has the following sequence in it :

<main>
    <first>.....</first>
    <second>....</second>
    <third>....</third>
    <second>...</second>
    <third>....</third>
    <first>....</first>
    <second>....</second>
</main>

    If I am on the first "first" element node, how can I write an
XPath expression to get the position of the second instance of the
"first" element? I can write

    followin-sibling::first[position() = 1]

....to locate the element, but I'm having trouble figuring out how to
find its position within the parent (main). The trouble appears to be
that if I put the above XPath expression with in the select of a
for-each, then, within the context of that for-each, the position of
the next "first" node is = 1. Somehow, I need to figure out how to
shift the context to the parent node, but an xsl:for-each select="../"
doesnt seem to solve my problem, because then I dont know how to test
for node equality between the children of the parent and the node that
I'm interested in. Any ideas?

    Actually, the real problem is for me to write an XPath expression
that will select all children of "main" from the first "first" upto
(but exluding) the next "first". Hence my desire to locate the
position of the next "first".

Thanks,
Kenneth


<Prev in Thread] Current Thread [Next in Thread>