Merge XML FILE

Here should go questions about transforming XML with XSLT and FOP.
Le Basque
Posts: 147
Joined: Sat Oct 19, 2013 8:21 am

Merge XML FILE

Post 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
adrian
Posts: 2855
Joined: Tue May 17, 2005 4:01 pm

Re: Merge XML FILE

Post 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
Adrian Buza
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
Post Reply