• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

XPath for atrib. name and value of node

 
Pavol Sestak
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello
i have specific problem with select from xml data via xpath. Here is the chunk of my xml file:
<zwk_export>
<record>
<field name="DEPOT_NR">1</field>
<field name="VALUE">463.18</field>
<field name="ART">1</field>
</record>
<record>
<field name="DEPOT_NR">1</field>
<field name="VALUE">5350.00</field>
<field name="ART">2</field>
</record>
...
<zwk_export>

Now i need to select all nodes "record" that has child "field" (note: all children are named "field") with attribute named "name" and value of that attrib. "ART" and value of the child node must be "1".
I tried these :
record[field/@name='ART' and (field/@name='ART') = '1']
record[field/@name = 'ART' and field/. = '1']

but these selected all nodes "field" that has child node "field" with attribute "name" and value of that attribute "ART" and has child "field" with value "1" (e.g. with child "DEPOT_NR" with value "1")but it is not able to select only "record" with such child:
<field name="ART">1</field>

The main problem is it mixes child <field name="ART">1</field>
and <field name="DEPOT_NR">1</field> but i do need identify positively "records" only with child <field name="ART">1</field>.

Can anyone help me?
 
Pavol Sestak
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If someone is interested here is the solution:
record[field[@name='ART'][.='1']]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic