How to apply XSLT on XML with XInclude only

I have this xml file:

<?xml version="1.0"?>
<xi:include href="http://www.w3schools.com/dom/books.xml" 
            xmlns:xi="http://www.w3.org/2003/XInclude"/>

and I expected that it should lead to deleted XML files http://www.w3schools.com/dom/books.xmlat the time of processing.

For this purpose, I created this XSL file:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:fn="http://www.w3.org/2005/xpath-functions">
    <xsl:output method="xml"/>
    <xsl:template match="*">
        <xsl:copy-of select="//book/title"/>
    </xsl:template>
</xsl:stylesheet>

which, after XSL conversion, I expected to get XML output with header nodes from an XML file with a link.

However, this did not happen, the transformation only generated an empty file. I suspect that the command was XIncludenot executed.

So, how can I apply XSLT in an Xincluded XML file, if possible?

+5
source share
2 answers

OP xml , .

.

<xsl:template match="xi:include[@href][@parse='xml' or not(@parse)][fn:unparsed-text-available(@href)]">
 <xsl:apply-templates select="fn:document(@href)" />
</xsl:template>

... xi: include, :

  • href
  • XML- ( ).
  • .

, XML , , xi: include node.

...

<xsl:template match="xi:include[@href][@parse='text'][fn:unparsed-text-available(@href)]">
 <xsl:apply-templates select="fn:unparsed-text(@href,@encoding)" />
</xsl:template>

... . , @parse - "xml". , . UTF-8, , , UTF-16LE.

, , ...

<xsl:template match="xi:include[@href][@parse=('text','xml') or not(@parse)][not(fn:unparsed-text-available(@href))][xi:fallback]">
 <xsl:apply-templates select="xi:fallback/text()" />
</xsl:template>

... , (, ), xi: include node .

+8

XInclude, XSD, - , , , . , , , . , Xerces XInclude.

0

All Articles