This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: seamless processing of multiple XML fragments


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]