XPath to compare two distinct attributes of two elements
Suppose I have this XML:
<x>
<e s="1" t="A"/>
<e s="2" t="A"/>
<e s="1" t="B"/>
</x>
Is there any way to write an xpath to find whether there are two distinct nodes named "e" which have the same value for @s but different values of @t. The first part is easy:
//e[@s = //e/@s]
as is the second part:
//e[@t != //e[@t]]
But I don't see any way to construct an xpath that compares two different attributes for two separate elements "e". Is there a way within the xpath syntax, or is it hopele开发者_C百科ss?
The requested nodes cannot be selected by a single XPath 1.0 expression.
If the hosting language is XSLT 1.0, then an expression using the current()
function can be constructed, that selects the desired nodes.
Use the following XPath 2.0 expression:
for $x
in
/*/e[@s
= (preceding-sibling::e
|
following-sibling::e
)
/@s
],
$y in /*/e[@s = $x/@s]
return
$x[not(@t = $y/@t)]
精彩评论