This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: seamless processing of multiple XML fragments
- To: xsl-list at lists dot mulberrytech dot com
- Subject: Re: [xsl] seamless processing of multiple XML fragments
- From: Francis Norton <francis at redrice dot com>
- Date: Mon, 03 Sep 2001 20:22:27 +0100
- References: <20010903182802.62032.qmail@web12606.mail.yahoo.com>
- Reply-To: xsl-list at lists dot mulberrytech dot com
What a sweet little problem - it really shows off how well the features
of XSLT work together.
Here's what you can do - wrote a transform (below) with just two
templates. Make one of them a pure pass-through template for everything
else, and the other a template for include elements. Them make the
include template pass through the contents of the referenced file.
Results below - HTH
Francis.
C:\xml>type t.xslt t.xml t2.xml t3.xml
t.xslt
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="node() | @*">
<xsl:copy>
<xsl:apply-templates select="node() | @*" />
</xsl:copy>
</xsl:template>
<xsl:template match="include">
<xsl:apply-templates select="document(@file)" />
</xsl:template>
</xsl:stylesheet>
t.xml
<root>
<a>
<b>B</b>
<include file="t2.xml"/>
</a>
<g>
<h>H</h>
<i>I</i>
</g>
</root>
t2.xml
<c>
<d>D</d>
<e>E</e>
<include file="t3.xml"/>
</c>
t3.xml
<f>F</f>
C:\xml>
C:\xml>saxon t.xml t.xslt
<?xml version="1.0" encoding="utf-8"?><root>
<a>
<b>B</b>
<c>
<d>D</d>
<e>E</e>
<f>F</f>
</c>
</a>
<g>
<h>H</h>
<i>I</i>
</g>
</root>
C:\xml>
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list