Johnathan Au
Johnathan Au

Reputation: 5362

How can I retrieve and store a value in a variable in XSLT?

I have an XML file with these values:

<query>
    <club>First</club>
</query>

And an XSLT file where I want to retrieve the value from the XML. How can I retrieve and store the club value in a variable in XSLT? I've done something similar in XSL by storing variables like this:

<xsl:variable name="testVar">
<xsl:choose>
    <xsl:when test="$variable = 'hello'">
        <xsl:text>msg=hello</xsl:text>
    </xsl:when>
    <xsl:otherwise>
        <xsl:text>msg=bye</xsl:text>
    </xsl:otherwise>
</xsl:choose>

But not with XPATH...

Upvotes: 1

Views: 4300

Answers (1)

G. Ken Holman
G. Ken Holman

Reputation: 4403

For XPath, just use the select= attribute to address your item:

<xsl:variable name="givenClub" select="/query/club"/>

... or, if your current node is query, then:

<xsl:variable name="givenClub" select="club"/>

Upvotes: 3

Related Questions