tags:

views:

43

answers:

1

I have the following code and I have to select all the nodes with id="text" but not the nodes that already have a parent with id="text":

<fo:block id="text">
  test00
  <fo:block id="text">
      test01
  </fo:block>
  <fo:block>
      test02
  </fo:block>
</fo:block>
<fo:block id="text">
    test03
</fo:block>

so in this example the query have to return only the two fo:block with content test00 and test03.

Thank you.

A: 

I'd go with something like this:

//fo:block[@id='text' and not(./*[@id='text'])]

I'm going to give it a test right now to make sure it's sane. Yeah. It returns text00 and text03, as required. So allow me to explain this expression.

//fo:block             # Select all fo:block elements in the document
[
  @id='text' and       # Get only those whose id attribute's value is "text"
  not(./*[@id='text']) # and whose children do not have id attributes equal to "text"
]
Welbog
thank you very much, you were so fast and now you're my new idol!!
Stefano