mailivres
mailivres

Reputation: 100

All elements with a following sibling equal to it

My XML structure:

<root>
  <!-- First -->
  <A>
      <B>123</B>
      <C>456</C>
  </A>

  <!-- Second -->
  <A>
      <B>999</B>
      <C>456</C>
  </A>

  <!-- Third -->
  <A>
      <B>123</B>
      <C>456</C>
  </A>

  <!-- Fourth-->
  <A>
      <B>123</B>
      <C>999</C>
  </A>

  <!-- Fifth -->
  <A>
      <X>123</X>
      <Y>456</Y>
  </A>
</root>

I want to find all A elements who have following siblings which are equal to it.

The desired result is just the first element, because it is equal to the third element.

I've tried this:

//A[.= following-sibling::A]

But as result I get the first and the third element. I guess the third element matches the fifth element, because the = operator just compares String values, right? Can you help me?

Can I even compute the position of the matched element in XPath or do I have to search for it in a XSL for loop?

Upvotes: 1

Views: 124

Answers (1)

Martin Honnen
Martin Honnen

Reputation: 167696

I think you are looking for the function deep-equal, see http://www.w3.org/TR/xpath-functions-30/#func-deep-equal, which you can use in //A[some $sibling in following-sibling::A satisfies deep-equal(. ,$sibling)].

Upvotes: 2

Related Questions