xml - Use variable ouside of scope in xslt -
here have small snippet has variable num_cpu under if condition, not able access outside if condition tag. how solve this?
how make num_cpu global can use multiple times outside loop?
<xsl:for-each select="t:container"> <xsl:if test="@name = 'cpu'"> <xsl:variable name="num_cpu" select="t:leaf/t:value/@value"/> </xsl:if> <xsl:value-of select="$num_cpu"/> </xsl:for-each>
to define global variable, place <xsl:variable>
element child of root stylesheet element.
in addition answer question in comment. how change value in if condition: xslt not imperative programming language can change value of variable.
if want pass value 1 template can use parameter e.g.
code snippet
<xsl:template match="foo"> <xsl:apply-templates select="bar"> <xsl:with-param name="pos" select="100"/> </xsl:apply-templates> </xsl:template> <xsl:template match="bar"> <xsl:param name="pos"/> <xsl:value-of select="$pos"/> </xsl:template>
Comments
Post a Comment