XPath and nodes?

J

JS

I have the below xml file:

<root>
<row order="0">
<data id="LT1" value="Width"/>
<data id="item" value="40 cm"/>
</row>
<row order="1">
<data id="LT1" value="Height"/>
<data id="item" value="20 cm"/>
</row>
</root>

I would like to define a XPath variable where id=LT1. I have tried:

Name: LT1
XPath: @id="LT1"

But when I use the "new" variable LT1 it returns nothing. How do I make a
new variable which only extracts data where id=LT1?
 
M

Martin Honnen

JS said:
I have the below xml file:

<root>
<row order="0">
<data id="LT1" value="Width"/>
<data id="item" value="40 cm"/>
</row>
<row order="1">
<data id="LT1" value="Height"/>
<data id="item" value="20 cm"/>
</row>
</root>

I would like to define a XPath variable where id=LT1. I have tried:

Name: LT1
XPath: @id="LT1"

But when I use the "new" variable LT1 it returns nothing. How do I make
a new variable which only extracts data where id=LT1?

It is not clear to me what exactly you want to achieve.
The XPath
/root/row[data[@id = 'LT1']]
would select all 'row' element children of the 'root' element which have
a 'data' child with the 'id' attribute value being 'LT1'.
If you do not want to select the 'row' elements but rather the 'data'
elements then use
/root/row/data[@id = 'LT1']
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,967
Messages
2,570,148
Members
46,694
Latest member
LetaCadwal

Latest Threads

Top