[英]XSLT Variable not working in xsl:value-of select=
I am working on some XSLT and I created a variable that will be used in a loop that will increment the index as it loops through, so the $index is the variable. 我正在一些XSLT上工作,我创建了一个变量,该变量将在循环中使用,该变量将在循环时增加索引,因此$ index是变量。
Here is what I have: 这是我所拥有的:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/xml">
<html>
<head>
<title><xsl:value-of select="module/name[@ID='SDCModule001']/title "/></title>
</head>
<body>
<xsl:apply-templates select="module/name[@ID='SDCModule001']"/>
</body>
</html>
</xsl:template>
<xsl:template name="stepList" match="name">
<xsl:param name="index" select="1" />
<xsl:param name="total" select="numSteps" />
<xsl:variable name="step" select="concat('step', $index)"/>
<xsl:if test="not($index = $total)">
<p><xsl:value-of select="step1" /><xsl:value-of select="$step" /></p>
</xsl:if>
</xsl:template>
</xsl:stylesheet>
When I put the information in a paragraph on the page ( <p><xsl:value-of select="step1" /> - <xsl:value-of select="$step" /></p>
), I get: 当我在页面上的段落(
<p><xsl:value-of select="step1" /> - <xsl:value-of select="$step" /></p>
)中放置信息时,我得到:
Do this 1 - step1 执行此操作1-步骤1
"Do this 1" is what is read from the XML and is correct. 从XML读取的内容是“做到这一点1”,它是正确的。 I am not sure why
<xsl:value-of select="$step" />
is bringing back "step1" and not "Do this 1" because <xsl:value-of select="$step" />
should translate into <xsl:value-of select="step1" />
. 我不确定为什么
<xsl:value-of select="$step" />
带回“ step1”而不是“ Do this 1”,因为<xsl:value-of select="$step" />
应该转换为<xsl:value-of select="step1" />
。
Any clue where I am going wrong here? 有什么线索我在这里出错吗?
Thank you. 谢谢。
XSLT is not a macro language. XSLT不是宏语言。
In a macro language, variables hold fragments of expression text, so if $x contains the text "delete file 'z'", then evaluating $x causes a file to be deleted. 在宏语言中,变量保存表达式文本的片段,因此,如果$ x包含文本“删除文件'z'”,则评估$ x会导致文件被删除。
XSLT is a conventional expression language in which variables hold values. XSLT是一种传统的表达语言,其中变量包含值。 Evaluating a variable containing the text "delete file 'z'" simply returns that text, it does not cause any files to be deleted.
评估包含文本“删除文件'z'”的变量只会返回该文本,不会导致任何文件被删除。 Similarly, if the value of variable $v1 is "$v2", the result of the evaluation is the string "$v2", not the contents of variable $v2.
同样,如果变量$ v1的值为“ $ v2”,则求值结果为字符串“ $ v2”,而不是变量$ v2的内容。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.