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

  • Home
  • SEARCH
  • 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 8922137
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T06:45:25+00:00 2026-06-15T06:45:25+00:00

I have an xml file as below propNode.xml <NODES> <NODE> <NODELINE CLASS=Item TYPE=Item >

  • 0

I have an xml file as below
propNode.xml

<NODES>
  <NODE>
<NODELINE CLASS="Item" TYPE="Item" >
  <ATTR_NODES>
    <ATTR_NODE NAME="myName" />
    <ATTR_NODE NAME="myDesc />
  </ATTR_NODES>
</NODELINE>
<NODELINE CLASS="Item1" TYPE="Item1" >
  <ATTR_NODES>
    <ATTR_NODE NAME="myName1" />
    <ATTR_NODE NAME="myDesc1" />
  </ATTR_NODES>
</NODELINE>
<NODELINE CLASS="Item2" TYPE="Item2" >
  <ATTR_NODES>
    <ATTR_NODE NAME="myName2" />
    <ATTR_NODE NAME="myDesc2" />
  </ATTR_NODES>
</NODELINE>
</NODE>
</NODES>

I want to read this xml and using it, I need to merge the following two xml files
source.xml

<NODES>
  <NODE>
<NODELINE CLASS="Item" TYPE="Item" >
  <ATTR_NODES>
    <ATTR_NODE NAME="myName" VALUE="myNameValue" />
    <ATTR_NODE NAME="myDesc" VALUE="test-myDescValue" />
<ATTR_NODE NAME="myId" VALUE="test-myIdValue" />
  </ATTR_NODES>
</NODELINE>
<NODELINE CLASS="Item1" TYPE="Item1" >
  <ATTR_NODES>
    <ATTR_NODE NAME="myName1" VALUE="myNameValue1" />
    <ATTR_NODE NAME="myDesc1" VALUE="myDescValue1"/>
<ATTR_NODE NAME="myId1" VALUE="myIdValue1" />
  </ATTR_NODES>
</NODELINE>
<NODELINE CLASS="Item2" TYPE="Item2" >
  <ATTR_NODES>
    <ATTR_NODE NAME="myName2" VALUE="test-myNameValue2" />
    <ATTR_NODE NAME="myDesc2" VALUE="myDescValue2"/>
<ATTR_NODE NAME="myId2" VALUE="test-myIdValue2" />
  </ATTR_NODES>
</NODELINE>
  </NODE>
</NODES>

And target.xml

<NODES>
  <NODE>
<NODELINE CLASS="Item" TYPE="Item" >
  <ATTR_NODES>
    <ATTR_NODE NAME="myName" VALUE="myNameValue" />
    <ATTR_NODE NAME="myDesc" VALUE="myDescValue" />
<ATTR_NODE NAME="myId" VALUE="myIdValue" />
  </ATTR_NODES>
</NODELINE>
<NODELINE CLASS="Item1" TYPE="Item1" >
  <ATTR_NODES>
    <ATTR_NODE NAME="myName1" VALUE="myNameValue1" />
    <ATTR_NODE NAME="myDesc1" VALUE="myDescValue1"/>
<ATTR_NODE NAME="myId1" VALUE="myIdValue1" />
  </ATTR_NODES>
</NODELINE>
<NODELINE CLASS="Item2" TYPE="Item2" >
  <ATTR_NODES>
    <ATTR_NODE NAME="myName2" VALUE="myNameValue2" />
    <ATTR_NODE NAME="myDesc2" VALUE="myDescValue2"/>
<ATTR_NODE NAME="myId2" VALUE="myIdValue2" />
  </ATTR_NODES>
</NODELINE>
  </NODE>
</NODES>

The condition is reading the propNode.xml, if the value of @NAME matches in the source.xml and target.xml, then the values of @VALUE in the source.xml and target.xml needs to be compared and an output xml should be created as below:

desiredOutput.xml

<NODES>
  <NODE>
<NODELINE CLASS="Item" TYPE="Item" >
  <ATTR_NODES>
    <ATTR_NODE NAME="myName" SRCVALUE="myNameValue" TGTVALUE="myNameValue" ISDIFF="false" />
    <ATTR_NODE NAME="myDesc" SRCVALUE="test-myDescValue" TGTVALUE="myDescValue" ISDIFF="true" />
  </ATTR_NODES>
</NODELINE>
<NODELINE CLASS="Item1" TYPE="Item1" >
  <ATTR_NODES>
    <ATTR_NODE NAME="myName1" SRCVALUE="myNameValue1" TGTVALUE="myNameValue1" ISDIFF="false" />
    <ATTR_NODE NAME="myDesc1" SRCVALUE="myDescValue1" TGTVALUE="myDescValue1" ISDIFF="false" />
  </ATTR_NODES>
</NODELINE>
<NODELINE CLASS="Item2" TYPE="Item2" >
  <ATTR_NODES>
    <ATTR_NODE NAME="myName2" SRCVALUE="test-myNameValue2" TGTVALUE="myNameValue2" ISDIFF="true" /> />
    <ATTR_NODE NAME="myDesc2" SRCVALUE="myDescValue2" TGTVALUE="myDescValue2" ISDIFF="false" />
  </ATTR_NODES>
</NODELINE>
  </NODE>
</NODES>

The desiredOutput.xml should contain both the values of @VALUE from the source and the target if the value of @NAME selected in the propNode.xml. If the values of @VALUE are different then @ISDIFF should have a value “true” or else “false”.

Is this whole operation possible using xslt? Something like generating xsl using the propNode.xml and then applying it on the source.xml and the target.xml to generate the desired output? How would this xsl look like?

  • 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-15T06:45:26+00:00Added an answer on June 15, 2026 at 6:45 am

    Assuming that only the nodes (ATTR_NODE) present in propNode.xml need to be tested, the following XSLT should do the job:

    <?xml version="1.0" encoding="UTF-8"?>
    <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
         xmlns:my="some.uri" version="1.0">
    
        <xsl:template match="@*|node()">
            <xsl:copy>
                <xsl:apply-templates select="@* | node()"/>
            </xsl:copy>
        </xsl:template>
    
        <xsl:template match="ATTR_NODE">
            <xsl:variable name="NodeLine" select="../../@CLASS" />
            <xsl:variable name="AttrName" select="@NAME" />
            <xsl:variable name="SrcValue" select="document('source.xml')//NODELINE[@CLASS=$NodeLine]//ATTR_NODE[@NAME=$AttrName]/@VALUE" />
            <xsl:variable name="TgtValue" select="document('target.xml')//NODELINE[@CLASS=$NodeLine]//ATTR_NODE[@NAME=$AttrName]/@VALUE" />
            <xsl:element name="ATTR_NODE">
                <xsl:attribute name="NAME">
                    <xsl:value-of select="$AttrName"/>
                </xsl:attribute>
                <xsl:attribute name="SRCVALUE">
                    <xsl:value-of select="$SrcValue" />
                </xsl:attribute>
                <xsl:attribute name="TGTVALUE">
                    <xsl:value-of select="$TgtValue" />
                </xsl:attribute>
                <xsl:attribute name="ISDIFF">
                    <xsl:value-of select="$SrcValue!=$TgtValue" />
                </xsl:attribute>
            </xsl:element>
        </xsl:template>
    </xsl:stylesheet>
    

    The identity template is used to traverse and copy propNode, with special processing for each ATTR_NODE checks VALUE in source and target, and then evaluated for equality. I’ve assumed that NODE_LINE/@CLASS is sufficient to establish the identity of the NODE_LINE – if it isn’t, then you’ll need to add additional checking e.g. @TYPE as well.

    The xslt is run against propnode.xml, and source.xml and target.xml must be present in the same folder.

    Output

    <?xml version="1.0" encoding="utf-8"?>
    <NODES>
        <NODE>
            <NODELINE CLASS="Item" TYPE="Item">
                <ATTR_NODES>
                    <ATTR_NODE NAME="myName" SRCVALUE="myNameValue" TGTVALUE="myNameValue" ISDIFF="false" />
                    <ATTR_NODE NAME="myDesc" SRCVALUE="test-myDescValue" TGTVALUE="myDescValue" ISDIFF="true" />"
                </ATTR_NODES>
            </NODELINE>
            <NODELINE CLASS="Item1" TYPE="Item1">
                <ATTR_NODES>
                    <ATTR_NODE NAME="myName1" SRCVALUE="myNameValue1" TGTVALUE="myNameValue1" ISDIFF="false" />
                    <ATTR_NODE NAME="myDesc1" SRCVALUE="myDescValue1" TGTVALUE="myDescValue1" ISDIFF="false" />
                </ATTR_NODES>
            </NODELINE>
            <NODELINE CLASS="Item2" TYPE="Item2">
                <ATTR_NODES>
                    <ATTR_NODE NAME="myName2" SRCVALUE="test-myNameValue2" TGTVALUE="myNameValue2" ISDIFF="true" />
                    <ATTR_NODE NAME="myDesc2" SRCVALUE="myDescValue2" TGTVALUE="myDescValue2" ISDIFF="false" />
                </ATTR_NODES>
            </NODELINE>
        </NODE>
    </NODES>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the below XML file <?xml version=1.0 encoding=iso-8859-1?> <DATASET> <TYPE>success</TYPE> <RECORD> <DATA type=email>eeee@eee.net</DATA>
I have xml file below: <?xml version=1.0 encoding=utf-8 ?> <?xml-stylesheet version=1.0 type=text/xml href=template.xsl ?>
I have xml file as below: <Name ns1:translate=yes>Overview</Name> <TextValue>Start</TextValue> <Title ns1:translate=yes>This is a book</Title>
I have a XML file like the below: <clients> <client> <id>YYYY</id> <name>XXXX</name> <desc>ZZZZ</desc> <trade_info>
I have an xml file like down below. I want to get pharmacies nodes'
I have s special xml file like below: <alarm-dictionary source=DDD type=ProxyComponent> <alarm code=402 severity=Alarm
i have xml file like Below and Device class and i want get List<Device>
i have 2 xml file as below: staff.xml <staff> <person> <PID>1</PID> <name>John</name> </person> <person>
I have an xml file likes below. <?xml version=1.0 encoding=utf-8 ?> <Book> <Title>Title</Title> <Content>Content</Content>
I have a xml file as below: <?xml version=1.0 encoding=UTF-8 standalone=no?> <RULES> <RULE DESCRIPTION=

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.