3

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.

2 Answers 2

3

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

Sign up to request clarification or add additional context in comments.

1 Comment

Here's another link that might help: w3.org/TR/xslt#attribute-value-templates You can also declare your variable using select to avoid creating an unnecessary tree: <xsl:variable name="test" select="'123'"/>
0

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>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.