1

suppose I have the following elements:

<?xml version="1.0"?>
<!DOCTYPE factory[
<!ELEMENT factorry (worker)+>
<!ELEMENT worker (#PCDATA)>
<!ATTLIST worker id ID #REQUIRED
                 boss IDREF #IMPLIED>
]>
<factory>
   <worker id="i1"> jon </worker>
   <worker id="i2" boss="i1"> sean </worker>
   <worker id="i3" boss="i2"> jerry </worker>
   <worker id="i4" boss="i3"> berry </worker>
</factory>

Now I want to write XPATH query that will give me all the bosses of the bosses, so in this example I want the result to be:

<worker id="i1"> jon < /worker>
<worker id="i2" boss="i1"> sean </worker>

Because Jon is Sean's boss, and Sean is Jerry's boss, and the same logic for Sean.
I know that if I write id(//worker/@boss) I get John, Sean and Jerry, so I want to apply the same logic again on this group, but I don't know how to do it.

sel
  • 483
  • 5
  • 16

1 Answers1

1

Two steps recursiton of your expression should give the result you need

//worker[@id=//worker[@id=//worker/@boss]/@boss]/text()

returns

Text='jon'
Text='sean'
splash58
  • 26,043
  • 3
  • 22
  • 34