Page 1 of 1
Merge XML FILE
Posted: Wed Mar 05, 2014 11:47 am
by Le Basque
Hi,
I have 2 xml file
File 1:
Code: Select all
<a>
<b>xxxxxx</b>
<c>yyyyyyy</c>
<d>
<table/>
</d>
</a>
File 2:
Code: Select all
<table>
<row><col>ssssss</col><col>rrrrrrr</col></row>
</table>
I want :
Code: Select all
<a>
<b>xxxxxx</b>
<c>yyyyyyy</c>
<d>
<table>
<row><col>ssssss</col><col>rrrrrrr</col></row>
</table>
</d>
</a>
I do not know how this merge in XSLT
Thank you
Re: Merge XML FILE
Posted: Wed Mar 05, 2014 12:54 pm
by adrian
Hi,
You can use a copy stylesheet (e.g. Oxygen/samples/xhtml/copy.xsl) with a small modification that treats the
table element individually.
e.g. The stylesheet is applied on the first XML and it's expected that the second XML is named
s2.xml.
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml"/>
<!-- Match document -->
<xsl:template match="/">
<xsl:apply-templates mode="copy" select="."/>
</xsl:template>
<!-- Deep copy template -->
<xsl:template match="*|text()|@*" mode="copy">
<xsl:message><xsl:value-of select="."/></xsl:message>
<xsl:copy>
<xsl:apply-templates mode="copy" select="@*"/>
<xsl:apply-templates mode="copy"/>
</xsl:copy>
</xsl:template>
<xsl:template match="table" mode="copy">
<xsl:copy>
<xsl:apply-templates select="document('s2.xml')/table/*" mode="copy"/>
</xsl:copy>
</xsl:template>
<!-- Handle default matching -->
<xsl:template match="*"/>
</xsl:stylesheet>
Regards,
Adrian