EXAMPLE:
My XML:
<root>
<a>
<b>1</b>
<b>1</b>
<b>2</b>
</a>
<a>
<b>1</b>
<b>2</b>
</a>
<a>
<b>1</b>
</a>
</root>
//a/b != ./b
Thanks for replies.
To get the number of different values for all /*/a/b
element nodes, you can count the distinct values of those elements:
count(/*/a/b[not(. = preceding::b)])
This expression will return 1 if there is one distinct value, 2 if two (as in your case) or 0 if there are no /*/a/b
elements in the document.
PHP Example:
<?php
$buffer = <<<XML
<root>
<a>
<b>1</b>
<b>1</b>
<b>2</b>
</a>
<a>
<b>1</b>
<b>2</b>
</a>
<a>
<b>1</b>
</a>
</root>
XML;
$doc = new DOMDocument();
$doc->loadXML($buffer);
$xpath = new DOMXPath($doc);
echo $xpath->evaluate('count(/*/a/b[not(. = preceding::b)])'); # echoes 2