0

I am getting a particular value by using

<xsl:value-of select="@date" />

and i want to store this value as a variable say 'd' How can i do this and also tell me how can i use that caribale back in my template. Thanks in advance

1
  • Here's one I've been bitten by often: storing the results of boolean expressions in variables won't work the way you might expect. <variable name="x" select="1=2"/> will store the string "false" in x, and "false" is, of course, TRUE because it's a non-empty string. Commented Aug 9, 2009 at 13:24

2 Answers 2

3
<xsl:variable name="d" select="@date" />
<xsl:value-of select="$d" />

Looking through the basics might be worthwhile. ;-)

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

Comments

2

That would be

<xsl:variable name="date" select="@date" />

to declare a symbol referencing the node @date.

To use it later on you can reference that symbol by prefixing the name with $:

<xsl:value-of select="$date" />

Note that once the symbol is declared you cannot change its value in XSLT.

2 Comments

@divo: Casual nitpicking: You're not declaring a symbol with the value of @date, but rather one with a reference to the node.
Thanks Tomalak, my mistake. That's actually quite a difference.

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.