user1942634
user1942634

Reputation: 73

Using the value of a variable in XSLT

Can anyone help me to create a map using dynamic variable value as a key in XSLT 1.0

I have a variable addressID whose value is 123. I would like to use this as a key in a map

<xsl:value-of select="$addressID" /> // gives output 123

<my:map>
  <entry key="$addressID">1</entry>
</my:map>

Please suggest me the proper syntax to use a variable in key.

Upvotes: 3

Views: 739

Answers (2)

Rookie Programmer Aravind
Rookie Programmer Aravind

Reputation: 12154

CodeGroover is right, and you can also use attribute
provided example below

<my:map>
  <entry>
    <xsl:attribute name="key">
       <xsl:value-of select="$addressID"/>
    </xsl:attribute>
    <xsl:value-of select="'1'"/>
  </entry>
</my:map>

Upvotes: 0

CodeGroover
CodeGroover

Reputation: 2187

First, setup variable:

<xsl:variable name="addressID">123</xsl:variable>

Second, you can use it as follow:

<my:map>
  <entry key="{$addressID}">1</entry>
</my:map>

via http://www.w3.org/TR/xslt#variables

Upvotes: 3

Related Questions