XSLT to replace XInclude elements

Here should go questions about transforming XML with XSLT and FOP.
ACS_DJH
Posts: 2
Joined: Wed Jan 13, 2010 5:12 pm

XSLT to replace XInclude elements

Post by ACS_DJH »

I’m using oXygen 11.1 (build 2010010613). I have an XSLT that I’m using to transform an XML document. One of the changes I need to make is to replace <xi:include> tags with another element as required by downstream process. I have turned off XInclude processing under “XML | XML Parser” and under XSLT for XSLTProc and MSXML.NET. However, the <xsl:template> that I’ve added doesn’t seem to be executed and the result file still contains the <xi:include> tags. What do I need to do to have my template “match” the <xi:include> tags?

The template I have is:

<xsl:template match=”xi:include”>

</xsl:template>


An example file would be:

<?xml version=”1.0” encoding=”UTF-8”?>
<!DOCTYPE book PUBLIC… …>
<book dtd-version=”2” xml:lang=”EN”
xmlns:xlink=”http://www.w3.org/1999/xlink”
xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance”>
<book-meta>...</book-meta>
<body>
<xi:include href=”file.xml”
xmlns:xi=”http://www.w3.org/2001/XInclude”>
<xi:fallback><!--Fallback for “file.xml"-->
</xi:fallback>
</xi:include>


</body>
</book>

Thanks.
DJ
adrian
Posts: 2883
Joined: Tue May 17, 2005 4:01 pm

Re: XSLT to replace XInclude elements

Post by adrian »

Hello,

First you should have the namespace declaration for XInclude, so the template should look like this:

Code: Select all

<xsl:template match="xi:include" xmlns:xi="http://www.w3.org/2001/XInclude">
...
</xsl:template>
And then, assuming you have a template that matches the root(/) or the parent element of the xi:include, make sure you call xsl:apply-templates, something like this:

Code: Select all

<xsl:template match="/">
...
<xsl:apply-templates/>
...
</xsl:template>
Regards,
Adrian
Adrian Buza
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
ACS_DJH
Posts: 2
Joined: Wed Jan 13, 2010 5:12 pm

Re: XSLT to replace XInclude elements

Post by ACS_DJH »

Thanks. That helped and I was able to get it working.
Post Reply