Xml 如何在Firefox中执行多个XSL转换过程?

Xml 如何在Firefox中执行多个XSL转换过程?,xml,firefox,xslt,exslt,Xml,Firefox,Xslt,Exslt,我试图在多个过程中转换包含样式表的XML文档,但是每当我试图包含exsl:node set以使变量可用时,我将转换后的XML放入Firefox解析失败,注意加载样式表时出错:发生未知错误() 在XSLT1.0中,我没有发现任何其他技术可以进行多次转换,因此我相信Firefox和 我的代码如下: <?xml version="1.0" encoding="UTF-8"?> <?xml-stylesheet type="text/xml" href="#stylesheet"?&

我试图在多个过程中转换包含样式表的XML文档,但是每当我试图包含
exsl:node set
以使变量可用时,我将转换后的XML放入Firefox解析失败,注意
加载样式表时出错:发生未知错误()

在XSLT1.0中,我没有发现任何其他技术可以进行多次转换,因此我相信Firefox和

我的代码如下:

<?xml version="1.0"  encoding="UTF-8"?>
<?xml-stylesheet type="text/xml" href="#stylesheet"?>
<doc>
    <xsl:stylesheet id="stylesheet" version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
        <xsl:template match="xsl:stylesheet" mode="passone"/>
        <xsl:template match="@*|node()" mode="passone">
            <xsl:copy>
                <xsl:copy-of select="ancestor::node()[local-name()='inherit']/@*"/> <!-- take default from parent -->
                <xsl:copy-of select="@*"/> <!-- overwrite if applicable -->
                <xsl:apply-templates mode="passone"/>
            </xsl:copy>
        </xsl:template>
        <xsl:template match="@*|node()" mode="passtwo">
            <xsl:copy>
                <xsl:copy-of select="ancestor::node()[local-name()='inherit']/@*"/> <!-- take default from parent -->
                <xsl:copy-of select="@*"/> <!-- overwrite if applicable -->
                <xsl:apply-templates mode="passtwo"/>
            </xsl:copy>
        </xsl:template>
        <xsl:template match="@*|node()" mode="passthree">
            <xsl:copy>
                <xsl:copy-of select="ancestor::node()[local-name()='inherit']/@*"/> <!-- take default from parent -->
                <xsl:copy-of select="@*"/> <!-- overwrite if applicable -->
                <xsl:apply-templates mode="passthree"/>
            </xsl:copy>
        </xsl:template>
        <xsl:template match="*[local-name()='inherit']" mode="passthree">
            <xsl:apply-templates mode="passthree"/>
        </xsl:template>
        <xsl:template match="*[local-name()='template'][@define]" mode="passtwo"/>
        <xsl:template match="*[local-name()='template'][@insert]" mode="passtwo">
            <xsl:copy-of select="//*[local-name()='template'][@define=current()/@insert]/*"/>
            <xsl:apply-templates mode="passtwo"/>
        </xsl:template>
        <xsl:template match="/">
            <xsl:variable name="resultone">
                <xsl:apply-templates mode="passone" select="."/>
            </xsl:variable>
            <xsl:variable name="resulttwo">
                <xsl:apply-templates mode="passtwo" select="exsl:node-set($resultone)"/>
            </xsl:variable>
            <xsl:apply-templates mode="passthree" select="exsl:node-set($resulttwo)"/>
        </xsl:template>
    </xsl:stylesheet>


    <svg version="1.1" viewBox="0 0 26 14" xmlns="http://www.w3.org/2000/svg">
        <template define="row">
            <rect/>
            <rect x="4"/>
            <rect x="8"/>
            <rect x="12"/>
            <rect x="16"/>
            <rect x="20"/>
            <rect x="24"/>
        </template>
        <inherit width="2" height="2">
            <template insert="row"/>
            <inherit y="4">
                <template insert="row"/>
            </inherit>
            <inherit y="8">
                <template insert="row"/>
            </inherit>
            <inherit y="12">
                <template insert="row"/>
            </inherit>
        </inherit>
    </svg>
</doc>

预期结果是:

<?xml version="1.0" encoding="UTF-8"?>
<svg version="1.1" viewBox="0 0 26 14" xmlns="http://www.w3.org/2000/svg">
    <rect width="2" height="2"/>
    <rect x="4" width="2" height="2"/>
    <rect x="8" width="2" height="2"/>
    <rect x="12" width="2" height="2"/>
    <rect x="16" width="2" height="2"/>
    <rect x="20" width="2" height="2"/>
    <rect x="24" width="2" height="2"/>
    <rect x="24" y="4" width="2" height="2"/>
    <rect x="20" y="4" width="2" height="2"/>
    <rect x="16" y="4" width="2" height="2"/>
    <rect x="12" y="4" width="2" height="2"/>
    <rect x="8" y="4" width="2" height="2"/>
    <rect x="4" y="4" width="2" height="2"/>
    <rect y="4" width="2" height="2"/>
    <rect y="8" width="2" height="2"/>
    <rect x="4" y="8" width="2" height="2"/>
    <rect x="8" y="8" width="2" height="2"/>
    <rect x="12" y="8" width="2" height="2"/>
    <rect x="16" y="8" width="2" height="2"/>
    <rect x="20" y="8" width="2" height="2"/>
    <rect x="24" y="8" width="2" height="2"/>
    <rect x="24" y="12" width="2" height="2"/>
    <rect x="20" y="12" width="2" height="2"/>
    <rect x="16" y="12" width="2" height="2"/>
    <rect x="12" y="12" width="2" height="2"/>
    <rect x="8" y="12" width="2" height="2"/>
    <rect x="4" y="12" width="2" height="2"/>
    <rect y="12" width="2" height="2"/>
</svg>

exsl:node set
描述了命名空间中带有前缀
exsl
的函数
节点集
。与任何其他名称空间一样,此前缀和名称空间在默认情况下不可用,但必须声明
具体而言,
节点集
存在于EXSLT的公共模块中,其名称空间为
http://exslt.org/common

这意味着您必须添加
xmlns:exsl=”http://exslt.org/common“
添加到
xsl:stylesheet
元素,这将使此命名空间在
exsl
前缀下可用,并使您能够将所需函数用作
exsl:node set

除此之外,使用模式仅应用特定模板,将结果管道化到变量中,并将其作为
apply templates
的输入,如给定源中所示,这是正确的方法


感谢for。

Firefox确实支持
exsl:node set
,但当然您必须声明名称空间才能使用它。一个简单的例子是,我无法理解带有嵌入式样式表的代码。当您的代码在浏览器之外使用XSLT 1处理器(如xsltproc、Xalan或Saxon 6)运行时,是否会产生正确的结果?谢谢,我完全没有意识到这一点(我与google fu一起拼凑了这个怪物,但对XSLT或XML一无所知,也没有提到这一点)。这使我能够调试转换,结果是,passone/two的继承/复制应用程序分别传递了两个/三个模板,而不是传递了一个/两个模板。我修好了,现在它可以工作了我非常感谢你。您想在答案中写入名称空间声明要求,还是我应该这样做?