brentfraser
brentfraser

Reputation: 77

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.

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:

Do this 1 - step1

"Do this 1" is what is read from the XML and is correct. 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" />.

Any clue where I am going wrong here?

Thank you.

Upvotes: 0

Views: 903

Answers (1)

Michael Kay
Michael Kay

Reputation: 163282

XSLT is not a macro language.

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.

XSLT is a conventional expression language in which variables hold values. Evaluating a variable containing the text "delete file 'z'" simply returns that text, it does not cause any files to be deleted. Similarly, if the value of variable $v1 is "$v2", the result of the evaluation is the string "$v2", not the contents of variable $v2.

Upvotes: 2

Related Questions