I have an XML structure like the following:
<inventory>
<location>
<category>
<children>
<book>
<title>Harry Potter</title>
<price>$28.50</price>
</book>
<cd>
<title>Frozen</title>
<price>12.8</price>
</cd>
</children>
</category>
<category>
<adult>
<book>
<title>Da vinci code</title>
<price>32.50</price>
</book>
<cd>
<title>Da vinci code</title>
<price>13.80</price>
</cd>
</adult>
</category>
</location>
<location>
<category>
<cooking>
<book>
<title>everyday Italian</title>
<price>30.50</price>
</book>
</cooking>
</category>
</location>
</inventory>
What I want to print is:
Location category# category title price 1 1 children Harry 28.50 2 1 cooking everyday... 30.50 1 2 cd Da vinci code 13.8
If I'm currently on each of the <title>
elements, how do I get the position of <location>
and <category>
?
What I've tried:
count(ancestor::location/preceding-silbing::location) + 1
count(ancestor::category/preceding-silbing::category) + 1
But none of them work.
count(ancestor::location[1]/preceding-sibling::location) + 1
andcount(ancestor::category[1]/preceding-sibling::category) + 1
– Burkart