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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T14:08:58+00:00 2026-06-17T14:08:58+00:00

I would like to be able to compare two nodes based on the values

  • 0

I would like to be able to compare two nodes based on the values of their child nodes. Testing node equality with the = operator just compares the string values of the respective nodes. I would like to compare them based on values in their child nodes.

To be a bit more specific, I would like <a> and <b> (below) to be equal, because the values of @id are the same for <c> elements that have matching @type attributes also have matching @id attributes.

<a>
    <c type="type-one" id="5675"/>
    <c type="type-two" id="3423"/>
    <c type="type-three" id="9088"/>
</a>
<b>
    <c type="type-one" id="5675"/>
    <c type="type-two" id="3423"/>
</b>

But these would be different:

<a>
    <c type="type-one" id="5675"/>
</a>
<b>
    <c type="type-one" id="2342"/>
</b>

The only solution I can begin to see involves a laborious comparison with a for-each statement, which I would like to avoid if possible.

If possible I would like to stick with XSLT 1.0. I am using xsltproc.

  • 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-17T14:09:00+00:00Added an answer on June 17, 2026 at 2:09 pm

    First of all, the relation called “equals” cannot have that name.

    “Equals” means that the relation is an equivalence relation. By definition any equivalence relation ~ must be:

    1. Reflexive: x ~ x .

    2. Symmetric: if x ~ y then y ~ x

    3. Transitive: if x ~ y and y ~ z then x ~ z .

    Here is an example, showing that the proposed “equals” relation isn’t transitive:

    x is:

    <a>
        <c type="type-one" id="5675"/>
        <c type="type-two" id="3423"/>
        <c type="type-three" id="9088"/>
    </a>
    

    y is:

    <b>
        <c type="type-one" id="5675"/>
        <c type="type-two" id="3423"/>
        <c type="type-four" id="1234"/>
    </b>
    

    z is:

    <b>
        <c type="type-three" id="3333"/>
        <c type="type-four" id="1234"/>
    </b>
    

    Now, we can see that x ~ y and y ~ z. However, clearly this doesn’t hold: x ~ z

    This said, I am calling the relation “matches” and it is relaxed and not “equals”.

    Here is a solution to the problem, with the above adjustment:

    Do note that this cannot be expressed with a single XPath expression, because XPath 1.0 (used within an XSLT 1.0 transformation) doesn’t have range variables.

    <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:call-template name="matches">
           <xsl:with-param name="pElem1" select="a"/>
           <xsl:with-param name="pElem2" select="b"/>
         </xsl:call-template>
     </xsl:template>
    
     <xsl:template name="matches">
       <xsl:param name="pElem1" select="/.."/>
       <xsl:param name="pElem2" select="/.."/>
    
       <xsl:variable name="vMisMatch">
           <xsl:for-each select="$pElem1/c[@type = $pElem2/c/@type]">
            <xsl:if test=
               "$pElem2/c[@type = current()/@type and not(@id = current()/@id)]">1</xsl:if>
           </xsl:for-each>
       </xsl:variable>
    
       <xsl:copy-of select="not(string($vMisMatch))"/>
     </xsl:template>
    </xsl:stylesheet>
    

    When this transformation is applied on the following XML document:

    <t>
        <a>
            <c type="type-one" id="5675"/>
            <c type="type-two" id="3423"/>
            <c type="type-three" id="9088"/>
        </a>
        <b>
            <c type="type-one" id="5675"/>
            <c type="type-two" id="3423"/>
        </b>
    </t>
    

    the wanted, correct result is produced:

    true
    

    When the same transformation is applied on this XML document:

    <t>
        <a>
            <c type="type-one" id="5675"/>
            <c type="type-two" id="3423"/>
            <c type="type-three" id="9088"/>
        </a>
        <b>
            <c type="type-one" id="5675"/>
            <c type="type-two" id="9876"/>
        </b>
    </t>
    

    again the correct result is produced:

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

Sidebar

Related Questions

I would like to be able to compare two classes derived from the same
I would like to be able to compare the asm generated by visual studio
I would like to be able to compare multiple strings with each other and
I would like to compare two lists (two rows of a data frame) and
I would like to compare two collections (in C#), but I'm not sure of
I would like to compare two different sets of data on the same imshow
I would like to compare three columns in two files and third column can
Would like to be able to set colors of headings and such, different font
I would like to be able to output the name of a variable, along
I would like to be able to print in the logs a message for

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.