Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do I identify duplicate nodes in XPath 1.0 using an XPathNavigator to evaluate?
    text
    copied!<p>I am trying to identify duplicate serial numbers from the following xml using XPath 1.0 and then evaluating it in .Net using an <code>XPathNavigator</code>.</p> <pre><code>&lt;?xml version="1.0" encoding="utf-16"?&gt; &lt;Inventory xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"&gt; &lt;Items&gt; &lt;Item&gt; &lt;SerialNumber&gt;1111&lt;/SerialNumber&gt; &lt;/Item&gt; &lt;Item&gt; &lt;SerialNumber&gt;1112&lt;/SerialNumber&gt; &lt;/Item&gt; &lt;Item&gt; &lt;SerialNumber&gt;1112&lt;/SerialNumber&gt; &lt;/Item&gt; &lt;/Items&gt; &lt;/Inventory&gt; </code></pre> <p>I tried to do this by evaluating this</p> <pre><code>//Items/Item/SerialNumber </code></pre> <p>expression in a custom XSLT Context Function (implementing <code>IXsltContextFunction</code> <a href="http://msdn.microsoft.com/en-us/library/dd567715" rel="nofollow">like this MSDN example</a>) in .Net but the Invoke function gets called one result at a time so I have no visibility of the other results to find duplicates.</p> <p><strong>1) Is there a way of doing this using a single XPath 1.0 expression?</strong></p> <p>OR</p> <p><strong>2) Is there a way of passing in an array of elements into a single Invoke call of the custom XSLT Context Function class?</strong> I'm working in VB.Net but am happy with any C# examples anyone can share. </p> <p>Thanks,</p> <p>Gavin</p> <p><strong>Edit</strong></p> <p>Thanks to O R Mapper and Dimitre for their responses. I initially accepted O R Mapper's response since it did do what I asked. I've since accepted Dimitre's answer since I like that it provides a distinct list of values. Both responses very helpful though!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload