8

I am having trouble constructing a single XPath statement to return two different sets of attributes.

For example take the following XML document:

<root>
 <line name="one" alpha="a1" beta="b1"/>
 <line name="two" alpha="a2" beta="b2"/>
 <line name="three" alpha="a3" beta="b3"/>
</root>

If I use the following XPath statement:

//@alpha

It yields the following attribute set:

alpha="a1"
alpha="a2"
alpha="a3"

What statement do I use to yield the following attribute set:

alpha="a1"
alpha="a2"
alpha="a3"
beta="b1"
beta="b2"
beta="b3"
Malachi
  • 3,205
  • 4
  • 29
  • 46
chinna
  • 535
  • 1
  • 6
  • 15

2 Answers2

14

By using the | operator in an XPath expression you can select several paths:

//@alpha | //@beta
Richard Parnaby-King
  • 14,703
  • 11
  • 69
  • 129
Oppositional
  • 11,141
  • 6
  • 50
  • 63
12
//@*[name()='alpha' or name()='beta']
Mads Hansen
  • 63,927
  • 12
  • 112
  • 147