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

Re: Set variable via contents of <variable> element

Subject: Re: Set variable via contents of <variable> element
From: Martin Honnen <Martin.Honnen@xxxxxx>
Date: Thu, 17 Dec 2009 14:38:09 +0100
Re:  Set variable via contents of <variable> element
Rowan Sylvester-Bradley wrote:
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'"/>

That way the variable 'myvariable' is of type string.

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

That way, with XSLT 1.0, the variable 'myvariable is of type result tree fragment. With XSLT 2.0, the variable is of type document-node() I think.

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

Do you use XSLT 1.0 or 2.0?

With 2.0, are you aware of the XPath 2.0
  if (condition) then expression1 else expression2
conditional expression that might help to use
  <xsl:variable name="myvariable"
                select="if (someCondition) then foo else bar"/>
to use the select attribute.

For XSLT 2.0 also http://www.w3.org/TR/xslt20/#variable-values might help, in particular that table explaining how combining the 'select' attribute and/or the 'as' attribute and/or the content of xsl:variable decide the type of the variable.


	Martin Honnen

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.