views:

48

answers:

2

I've got the following structured XML file:

   <w:document>
      <w:body>
        <w:p>
           <w:r>
              <w:t/>
           </w:r>
        </w:p>
        <w:p>
           <w:r>
              <w:t/>
           </w:r>
        </w:p>
        <w:p>
           <w:r>
              <w:instrText/>
           </w:r>
        </w:p>
        <w:p>
           <w:r>
              <w:t/>
           </w:r>
        </w:p>
        <w:p>
           <w:r>
              <w:instrText/>
           </w:r>
        </w:p>
        <w:p>
           <w:r>
              <w:t/>
           </w:r>
        </w:p>
     </w:body>
  </w:document>

and I'm trying desperately to find an XPath expression to select all <w:t> nodes that are between two <w:instrText> nodes. <w:t> nodes basically appear freely all around the XML document, but I'm only interested in those between two <w:instrText> nodes.

Any help is greately appreciated.

+1  A: 

Is it not as simple as: //x/t ?

sgrassie
+2  A: 

I'm trying desperately to find an XPath expression to select all <w:t> nodes that are between two <w:instrText> nodes

/w:document/w:body/w:p/w:r/w:instrText/following::w:t
      [count(.|/w:document/w:body/w:p/w:r/w:instrText/preceding::w:t) =
       count(/w:document/w:body/w:p/w:r/w:instrText/preceding::w:t)]

Node set intersection expression

Alejandro
Thank you, that works nicely :-).
naacal
@naacal: You are wellcome.
Alejandro
@Alejandro: Could you link to an explanation of the node set intersection test? I always get confused by the count(.) style testing.
geoffc
@geoffc: unfortunately I can't find a preview for Dr. Micheal Kay book. This is know as Kaysan node set intersection expression, because he was the first to point out. How does it work? Mainly because `|` union operator results in a non duplicate node set. So, performing the union between a node with a node set that already contains this node, doesn't change the count (meaning it's included in set theory)
Alejandro