Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8155907
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T16:48:04+00:00 2026-06-06T16:48:04+00:00

I am trying to identify duplicate serial numbers from the following xml using XPath

  • 0

I am trying to identify duplicate serial numbers from the following xml using XPath 1.0 and then evaluating it in .Net using an XPathNavigator.

<?xml version="1.0" encoding="utf-16"?>
<Inventory xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <Items>
        <Item>
            <SerialNumber>1111</SerialNumber>
        </Item>
        <Item>
            <SerialNumber>1112</SerialNumber>
        </Item>
        <Item>
            <SerialNumber>1112</SerialNumber>
        </Item>
    </Items>
</Inventory>

I tried to do this by evaluating this

//Items/Item/SerialNumber

expression in a custom XSLT Context Function (implementing IXsltContextFunction like this MSDN example) 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.

1) Is there a way of doing this using a single XPath 1.0 expression?

OR

2) Is there a way of passing in an array of elements into a single Invoke call of the custom XSLT Context Function class? I’m working in VB.Net but am happy with any C# examples anyone can share.

Thanks,

Gavin

Edit

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!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T16:48:06+00:00Added an answer on June 6, 2026 at 4:48 pm

    Use:

    /*/*/Item
          [SerialNumber = following-sibling::Item/SerialNumber
         and
           not(SerialNumber = preceding-sibling::Item/SerialNumber)
          ]
    

    This selects just one Item element for any group of Item elements that have a SerialNumber child with the same string value.

    XSLT – based verification:

    <xsl:stylesheet version="1.0"
        xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
        <xsl:output omit-xml-declaration="yes" indent="yes"/>
        <xsl:strip-space elements="*"/>
    
     <xsl:template match="/">
         <xsl:copy-of select=
          "/*/*/Item
              [SerialNumber = following-sibling::Item/SerialNumber
             and
               not(SerialNumber = preceding-sibling::Item/SerialNumber)
              ]"/>
     </xsl:template>
    </xsl:stylesheet>
    

    When this transformation is applied on this XML document (based on the provided one, but made more interesting):

    <Inventory>
        <Items>
            <Item>
                <SerialNumber>1111</SerialNumber>
            </Item>
            <Item>
                <SerialNumber>2222</SerialNumber>
            </Item>
            <Item>
                <SerialNumber>2222</SerialNumber>
            </Item>
            <Item>
                <SerialNumber>2222</SerialNumber>
            </Item>
            <Item>
                <SerialNumber>1111</SerialNumber>
            </Item>
            <Item>
                <SerialNumber>1111</SerialNumber>
            </Item>
            <Item>
                <SerialNumber>3333</SerialNumber>
            </Item>
        </Items>
    </Inventory>
    

    the transformation evaluates the XPath expression and copies the selected nodes to the output:

    <Item>
       <SerialNumber>1111</SerialNumber>
    </Item>
    <Item>
       <SerialNumber>2222</SerialNumber>
    </Item>
    

    Finally, if you want to get just the SerialNumber duplicate values, use:

       /*/*/Item
              [SerialNumber = following-sibling::Item/SerialNumber
             and
               not(SerialNumber = preceding-sibling::Item/SerialNumber)
              ]
               /SerialNumber/text()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using Delphi XE 2 I've trying to identify the zoom direction to apply the
I am trying to identify a method for obtaining nearby wifi access points using
I'm trying to get the contents of an xml file using jQuery's ajax function.
I am trying to make a regex to identify relative src paths using PHP.
I'm trying to identify if this is an IIS issue or a code issue.
I am trying to identify when an action without authorization has been made. Is
I am trying to identify a screen in a multi-monitor setup to save some
I am trying to identify file types for directory entries (Windows Unix etc..). In
I am trying to identify all the nodes in a tree that lead to
I am trying to identify SQL INSERTS that occur when a record is viewed

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.