[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Set variable via contents of <variable> element

Subject: Set variable via contents of <variable> element
From: "Rowan Sylvester-Bradley" <rowan@xxxxxxxxxxxxxxxxxxxxx>
Date: Thu, 17 Dec 2009 13:22:26 -0000
 Set variable via contents of <variable> element
As I understand it, I can set the value of a variable in two ways:
1. By the "select" attribute of the <variable> element:
<xsl:variable name="myvariable" select="'myvalue'"/>

2. By the contents of the <variable> element:
<xsl:variable name="myvariable">
  My value

I can set the value of a new variable to the value of an existing variable
by the first method, and it works fine as in this example:
   <xsl:template match="item">
      <xsl:variable name="this" select="."/>
      <xsl:variable name="usethis" select="$this"/>

I can now use the variable $usethis to access elements of the current node
set, including ancestors of the current node, so the following works:
  <grandparentid><xsl:value-of select="$usethis/../../id"/></grandparentid>
Presumably in this case $usethis" must be a pointer or reference to the
current node in the input document (as opposed to a copy of the current
node) so I can navigate away from it through the input document to access
ancestors etc. (sorry if I'm not using the correct terms to describe what I

But how do I set the variable using the second method? I can't get it to
work in the same way. It would seem that I have to use copy-of or value-of
in the body of the <variable> element, but this doesn't achieve the same

The reason I need to do this is because I want to set the variable 'usethis'
to the result of a <choose> element which (as far as I know) I cannot
include in a "select" attribute. Also in my real example 'this' is a

Thanks - Rowan

Current Thread


Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
First Name
Last Name
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.