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?