user7232539
user7232539

Reputation:

XPath based on node indexes only

I have an XML :

<Section>
    <Paragraph>
        <Text>t1</Text>
        <Text>t2</Text>
    </Paragraph>
    <Paragraph>
        <Text>t3</Text>
        <Text>t4</Text>
    </Paragraph>
</Section>

and I know only element indexes, e.g., /0/1/0 i.e. first Section, second Paragraph, and its first Text. How can I translate '0/1/0' into a valid XPath that returns element where t3 is ?

Note that I don't know element names because they can differ but I only know sequence of indexes as in above example.

Many thanks

Upvotes: 0

Views: 25

Answers (1)

chrisis
chrisis

Reputation: 1993

For the example given this will work.

/element()[1]/element()[2]/element()[1]/text()

Upvotes: 1

Related Questions