Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/14.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 使用样式表更改节点集内的元素_Xml_Xslt_Xslt 1.0_Xslt 2.0 - Fatal编程技术网

Xml 使用样式表更改节点集内的元素

Xml 使用样式表更改节点集内的元素,xml,xslt,xslt-1.0,xslt-2.0,Xml,Xslt,Xslt 1.0,Xslt 2.0,我有一个接受空输入的样式表 并且需要将输出作为 <result> <Customers> <customer name="FirstName">John</customer> <customer name="FirstName">Kevin</customer> </Customers> </result>

我有一个接受空输入的样式表

并且需要将输出作为

    <result>
        <Customers>
            <customer name="FirstName">John</customer>
            <customer name="FirstName">Kevin</customer>
        </Customers>
    </result>

约翰
凯文
我现在在xsl中指定的结果是,我将从同一样式表中的其他服务调用中获得

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
xmlns:xs="http://www.w3.org/2001/XMLSchema" >

    <xsl:template match="/">

        <xsl:variable name="request">
            <result>
                <Customers>
                    <customer name="Name">John</customer>
                    <customer name="Name">Kevin</customer>
                </Customers>
            </result>
        </xsl:variable>

            <xsl:apply-templates select="$request/result/Customers"/>

    </xsl:template>

    <xsl:template match="node( ) | @*">
        <xsl:copy>
            <xsl:apply-templates select="@* | node( )"/>
        </xsl:copy>
    </xsl:template>
    <xsl:template match="customer/@name[. = 'Name']">
        <xsl:attribute name="name">FirstName</xsl:attribute>
    </xsl:template>
</xsl:stylesheet>

约翰
凯文
名字

但调用模板时出错。我的样式表出了什么问题?

你说的是接受空输入的
?不,XSLT只有在提供XML输入时才起作用(它可能很小:
),但它必须有XML输入。其他一切看起来都很好。。但根据您的预期输出,应用模板如下

<xsl:apply-templates select="$request/result"/>

您已经将其标记为
xslt-1.0
xslt-2.0
,但这些标记意味着相互排斥。上述XSLT只能在XSLT2.0中正常工作,而不能在XSLT1.0中正常工作。(在XSLT1.0中,
$request
变量是一个结果树片段,需要转换为扩展函数设置的节点)。您的XSLT处理器是否确实支持XSLT2.0?