Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xslt/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Xml 具有默认命名空间前缀的XSLT模板不匹配_Xml_Xslt - Fatal编程技术网

Xml 具有默认命名空间前缀的XSLT模板不匹配

Xml 具有默认命名空间前缀的XSLT模板不匹配,xml,xslt,Xml,Xslt,我试图编写一个XSLT过滤器转换,插入一个子元素。以下是输入XML: <?xml version="1.0" encoding="UTF-8"?> <root xmlns="http://example.org"> <child info="first"/> <child info="second"/> </root> 我的XSLT转换如下所示: <?xml version="1.0" encoding="U

我试图编写一个XSLT过滤器转换,插入一个子元素。以下是输入XML:

<?xml version="1.0" encoding="UTF-8"?>
<root xmlns="http://example.org">
    <child info="first"/>
    <child info="second"/>
</root>

我的XSLT转换如下所示:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
    xmlns="http://example.org" 
    xpath-default-namespace="http://example.org">

    <!-- insert new child element at front -->
    <xsl:template match="child[1]">
        <child info="very first"/>
        <xsl:copy>
            <xsl:apply-templates select="@* | node()"/>
        </xsl:copy>
    </xsl:template>

    <!-- standard copy template -->
    <xsl:template match="@* | node()">
        <xsl:copy>
            <xsl:apply-templates select="@* | node()"/>
        </xsl:copy>
    </xsl:template> 
</xsl:stylesheet>


复制模板可以正常工作,但应该执行特殊操作的模板不能。我已经试过其他帖子的几个建议,但都没有用。我可以运行XSLT 2.0,但使用前缀更改输入文件不是一个选项。

上面的XSLT确实插入了“第一个”子节点。看见您确定使用的是XSLT 2.0处理器吗?“复制模板工作正常,但本应执行特殊操作的模板不工作。”以何种方式不工作(或工作正常)?发布预期结果。添加
以输出您正在使用的XSLT版本。您的结果与XSLT1.0处理器应该提供的结果一致。您是对的:我使用的是XSLT1.0处理器。我正在使用Eclipse,并且确信如果处理器不能处理XSLT2.0,将会出现错误消息。在Saxon9中,它起作用了。