0

我正在尝试设置一个 XML 文档的样式,该文档使用 xinclude 来包含其他 xml 文件以实现模块化。我使用 Firefox 作为可视化转换的工具。(所有文件都在同一个文件夹中)目前我已经编写了以下 xsl:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                          xmlns:xi="http://www.w3.org/2001/XInclude"
                          exclude-result-prefixes='xsl xi'>
    <xsl:template match="/interfaces">
        <html>
            <head>
                <meta charset="UTF-8" content="text/html" http-equiv="Content-Type"/>
                <title>Messages</title>
            </head>
            <body>
                <xsl:apply-templates select="message"/>
            </body>
        </html>
    </xsl:template>

    <xsl:template match="message">
        <xsl:value-of select="@name"/><br/>
        <xsl:apply-templates select="xi:include[@href][@parse='xml' or not(@parse)]" />
    </xsl:template>

    <xsl:template match="xi:include">
        Should be outputed...<xsl:apply-templates select="document(@href)" />
    </xsl:template>

</xsl:stylesheet

要处理以下 xml:

<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type='text/xsl' href='messages-xsl.xml'?>

<interfaces>
    <message name="some_message">
        <xi:include href="some_message.xml" xmlns:xi="http://www.w3.org/2003/XInclude"/>
    </message>
</interfaces>

我知道 stackoverflow 上的一些帖子提出了类似的问题,但到目前为止我无法解决这个问题。提前致谢。

4

1 回答 1

1

您的 XSLT 有xmlns:xi="http://www.w3.org/2001/XInclude",而您的示例有xmlns:xi="http://www.w3.org/2003/XInclude",您将需要在 XSLT 和 XML 中使用相同的名称空间。为了获得更好的错误消息,我建议version="1.0"在 XSLT 中使用,因为 Firefox 使用 XSLT 1.0 处理器并切换到使用您的 version="2.0" 属性进行前向兼容处理。

于 2014-10-20T12:35:19.060 回答