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 6055833
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T08:18:31+00:00 2026-05-23T08:18:31+00:00

I have following xml. Note that node n1 and n3 have same children (order

  • 0

I have following xml. Note that node n1 and n3 have same children (order can be different). How can I write an XSL transformation to identify such nodes?

<Document>
    <Node name="n1">
        <Item value="v1">
        <Item value="v2">
        <Item value="v3">
    </Node>
    <Node name="n2">
        <Item value="p1">
        <Item value="p2">
        <Item value="p3">
    </Node>
    <Node name="n3">
        <Item value="v3">
        <Item value="v1">
        <Item value="v2">
    </Node>
</Document>
  • 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-05-23T08:18:32+00:00Added an answer on May 23, 2026 at 8:18 am

    Here is a complete XSLT 1.0 solution that is general enough so that it would produce correct results even when a Node is allowed to have children with any name:

    <xsl:stylesheet version="1.0"
     xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
     xmlns:ext="http://exslt.org/common" exclude-result-prefixes="ext">
     <xsl:output omit-xml-declaration="yes" indent="yes"/>
     <xsl:strip-space elements="*"/>
    
     <xsl:key name="kNodeBySign" match="Node" use="@signature"/>
    
     <xsl:template match="/*">
         <xsl:variable name="vrtfPass1">
          <xsl:apply-templates/>
         </xsl:variable>
    
         <xsl:apply-templates mode="pass2"
              select="ext:node-set($vrtfPass1)"/>
     </xsl:template>
    
     <xsl:template match="Node">
      <Node name="{@name}">
       <xsl:variable name="vSignature">
        <xsl:for-each select="*">
         <xsl:sort select="name()"/>
         <xsl:sort select="@value"/>
          <xsl:value-of select="concat(name(),'+++',@value)"/>
        </xsl:for-each>
      </xsl:variable>
    
      <xsl:attribute name="signature">
       <xsl:value-of select="$vSignature"/>
      </xsl:attribute>
      </Node>
     </xsl:template>
    
     <xsl:template match="/" mode="pass2">
      <xsl:for-each select=
        "Node[generate-id()
             =
              generate-id(key('kNodeBySign',@signature)[1])
             ]
        ">
    
        <Node name="{@name}">
          <xsl:variable name="vNodesInGroup">
            <xsl:for-each select=
              "key('kNodeBySign',@signature)[position()>1]">
              <xsl:value-of select="concat(@name, ' ')"/>
            </xsl:for-each>
          </xsl:variable>
    
          <xsl:attribute name="matches">
           <xsl:value-of select="$vNodesInGroup"/>
          </xsl:attribute>
        </Node>
      </xsl:for-each>
     </xsl:template>
    </xsl:stylesheet>
    

    when applied on this XML document:

    <Document>
        <Node name="n1">
            <Item value="v1"/>
            <Item value="v2"/>
            <Item value="v3"/>
        </Node>
        <Node name="n2">
            <Item value="p1"/>
            <Item value="p2"/>
            <Item value="p3"/>
        </Node>
        <Node name="n3">
            <Item value="v3"/>
            <Item value="v1"/>
            <Item value="v2"/>
        </Node>
        <Node name="n4">
            <Item value="p3"/>
            <Item value="v1"/>
            <Item value="v2"/>
        </Node>
        <Node name="n5">
            <Item value="v2"/>
            <Item value="v1"/>
            <Item value="v3"/>
        </Node>
        <Node name="n6">
            <Item value="v2"/>
            <Item value="v1"/>
            <Item value="v3"/>
            <Item value="v4"/>
        </Node>
        <Node name="n7">
            <Item value="v1"/>
            <Item value="v1"/>
            <Item value="v2"/>
            <Item value="v3"/>
            <Item value="v4"/>
        </Node>
    </Document>
    

    the wanted, correct result is produced:

    <Node name="n1" matches="n3 n5 "/>
    <Node name="n2" matches=""/>
    <Node name="n4" matches=""/>
    <Node name="n6" matches=""/>
    <Node name="n7" matches=""/>
    

    Explanation:

    1. This is a two-pass transformation.

    2. The result of the first pass is an XML fragment containing Node elements with their name attribute and one newly added attribute: signature. This is the concatenation of the names and values of all children (in normal, sorted form). The result of pass1 in this concrete case is the following:

    3. In pass 2 we use the Muenchian method for grouping all Node elements by their signature attribute. The first Node in every group is represented in the output with a new attribute matches whose value is the space-delimited concatenation of the name attributes of the remaining Node elements in the current group.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have something like the following xml that I need to deserialize (note I
I have the following xml that's sent to me from a web service. I'm
I have the following XML and I want to process it so that I
I have the following XSLT code that almost does what I want: <xsl:variable name=scoredItems
I have a quite stupid question. How can I make sure that my XML
I have the following XML structure: <?xml version=1.0 ?> <course xml:lang=nl> <body> <item id=787900813228567
I have the following xml I'd like to deserialize into a class <?xml version=1.0
I have the following XML document: <projects> <project> <name>Shockwave</name> <language>Ruby</language> <owner>Brian May</owner> <state>New</state> <startDate>31/10/2008
I have the following XML <?xml version=1.0?> <FileHeader xmlns=urn:schemas-ncr-com:ECPIX:CXF:FileStructure:020001 VersionNumber=020001 TestFileIndicator=P CreationDate=13012009 CreationTime=172852 FileID=0000000001
I have the following XML: <XMLDictionary> <a>b</a> <c>d</c> <e>f</e> </XMLDictionary> I'm trying to get

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.