Hi,
I have two xml files. I am trying to transform them using xslt. The xml
files are having few common tags. I want to merge them one below another by
adding two attributes. I have written xsl file also, attributes are getting
added but common elements are not getting merged as I want because of
multiple occurrence of "version" tag.
I am pasting my files below. Please help me out to get the Expected Output.
*File1.xml*
<?xml version="1.0" encoding="UTF-8"?>
<config>
<version>
<input00 version ="11"/>
<name00 name ="abc"/>
</version>
<version>
<input00 version ="22"/>
<name00 name ="def"/>
</version>
</config>
*File2.xml*
<?xml version="1.0" encoding="UTF-8"?>
<config>
<version>
<input00 version ="2"/>
<name00 name ="xyz"/>
</version>
<version>
<input00 version ="3"/>
<name00 name ="pqr"/>
</version>
<version>
<input00 version ="4"/>
<name00 name ="uvw"/>
</version>
</config>
*Expected Output.xml*
<config>
<version Label="test" sNo="test">
<input00 version ="2"/>
<name00 name ="xyz"/>
</version>
<version Label="test" sNo="test">
<input00 version ="3"/>
<name00 name ="pqr"/>
</version>
<version Label="test" sNo="test">
<input00 version ="4"/>
<name00 name ="uvw"/>
</version>
<version Label="test" sNo="test">
<input00 version ="11"/>
<name00 name ="abc"/>
</version>
<version Label="test" sNo="test">
<input00 version ="22"/>
<name00 name ="def"/>
</version>
</config>
*file12.xsl*
<xsl:stylesheet version="2.0" xmlns:xsl="
http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()" />
</xsl:copy>
</xsl:template>
<xsl:template match="version">
<xsl:copy>
<xsl:attribute name="Level">
<xsl:value-of select="'test'"></xsl:value-of>
</xsl:attribute>
<xsl:attribute name="sNo">
<xsl:value-of select="'test'"></xsl:value-of>
</xsl:attribute>
<xsl:for-each select="/config/version">
<xsl:apply-templates select="/config/version/node()"/>
</xsl:for-each>
<xsl:apply-templates select="document('File1.xml')/config/version/node()" />
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
Thanks,
BR,
Varun
--~----------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
EasyUnsubscribe: http://lists.mulberrytech.com/unsub/xsl-list/1167547
or by email: xsl-list-unsub(_at_)lists(_dot_)mulberrytech(_dot_)com
--~--