Xml 从其他模板继承变量
我正在尝试将变量从上一个模板继承到当前模板 这是我的xsl,想知道是否有什么地方出错:Xml 从其他模板继承变量,xml,xslt,xslt-1.0,xslt-2.0,Xml,Xslt,Xslt 1.0,Xslt 2.0,我正在尝试将变量从上一个模板继承到当前模板 这是我的xsl,想知道是否有什么地方出错: <xsl:template match="child1"> <xsl:variable name="props-value"> <xsl:value-of select="VALUE1"/> </xsl:variable> <xsl:apply-templates select="attribute[matche
<xsl:template match="child1">
<xsl:variable name="props-value">
<xsl:value-of select="VALUE1"/>
</xsl:variable>
<xsl:apply-templates select="attribute[matches(.,'=@')]">
<xsl:with-param name="props-value" select="$props-value" />
</xsl:apply-templates>
</xsl:template>
<xsl:template match="attribute[matches(.,'=@')]">
<xsl:param name="props-value"/>
<xsl:copy>
<xsl:apply-templates select="@*"/>
<xsl:if test="$props_value = 'VALUE1'">
Value is true
</xsl:if>
</xsl:copy>
</xsl:template>
价值是真实的
预期输出:值为true。XSLT存在两个问题:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes" omit-xml-declaration="yes"/>
<xsl:template match="child1">
<xsl:variable name="props-value">
<xsl:value-of select=" 'VALUE1' "/>
</xsl:variable>
<xsl:apply-templates select="attribute">
<xsl:with-param name="props-value" select="$props-value" />
</xsl:apply-templates>
</xsl:template>
<xsl:template match="attribute">
<xsl:param name="props-value"/>
<xsl:copy>
<xsl:apply-templates select="@*"/>
<xsl:if test="$props-value = 'VALUE1'">
Value is true
</xsl:if>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
“VALUE1”
作为值。这与
元素匹配。我相信您希望选择“'VALUE1'”
(一个值为'VALUE1'的字符串)$props_value
,而参数使用连字符调用props value
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes" omit-xml-declaration="yes"/>
<xsl:template match="child1">
<xsl:variable name="props-value">
<xsl:value-of select=" 'VALUE1' "/>
</xsl:variable>
<xsl:apply-templates select="attribute">
<xsl:with-param name="props-value" select="$props-value" />
</xsl:apply-templates>
</xsl:template>
<xsl:template match="attribute">
<xsl:param name="props-value"/>
<xsl:copy>
<xsl:apply-templates select="@*"/>
<xsl:if test="$props-value = 'VALUE1'">
Value is true
</xsl:if>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
价值是真实的
应用于以下输入XML时:
<child1>
<attribute/>
</child1>
它生成以下输出XML:
<attribute>
Value is true
</attribute>
价值是真实的
请提供任何建议。。。