0
<courses>
<course number = "1" category = "A">
<title>B</title>
</course>
</courses>

I want to pick all @number has category= "A" I try to use //@number[@category/text()='A'], but it seem no work, So how can I get it

Caozy
  • 1
  • 1

2 Answers2

1

To get @number attribute value of <course> node with category='A':

//course[@category='A']/@number
RomanPerekhrest
  • 88,541
  • 4
  • 65
  • 105
0

Your XML is invalid, you need quotation marks around 1:

<course number="1" category = "A">

For attribute values, you never need text(). Use

//@number[../@category="A"]

It means:

  • //@number: select any number attribute
  • [...]: which satisfies the condition
  • ../: go up to the parent (element course or other)
  • @category: find a category attribute
  • ="A": which has the value A
Thomas Weller
  • 55,411
  • 20
  • 125
  • 222