Altova Mailing List Archives

Re: Transforming text into a variable name

From: "G. Ken Holman" <gkholman@-------------------->
Date: 11/2/1999 11:33:00 AM
At 99/10/20 11:16 -0700, Scott Sanders wrote:
Is there a way in XSLT to transform a attribute text value to a variable

No, but you can use an attribute's value to find a variable's declaration 
in the stylesheet, which may work for what you are looking for.

  For Example:

<search title="Search for record" var="test">

In the XSL I want to transform 'test' to the equivalent of <xsl:value-of

A working example is below.  If your variables are not result tree 
fragments, you'll have to do some awkward string manipulation since string 
values are specified inside of quotes.

I hope this helps.

......... Ken

T:\sanders>type sanders.xml
<?xml version="1.0"?>
<search title="Search for record" var="test1"/>
<search title="Search for another" var="test2"/>

T:\sanders>type sanders.xsl
<?xml version="1.0"?>
<!DOCTYPE xsl:stylesheet [<!ENTITY nl "&#xd;&#xa;">]>
<xsl:stylesheet xmlns:xsl=""

<xsl:variable name="test1">Value of first variable</xsl:variable>
<xsl:variable name="test2">Value of second variable</xsl:variable>

<xsl:template match="/">

<xsl:template match="search">
  <!--go to the stylesheet file and find the top-level
      variable declaration whose name attribute is equal
      to the current node's var attribute-->
  <xsl:value-of select="@title"/>: '<xsl:value-of


T:\sanders>xt sanders.xml sanders.xsl
Search for record: 'Value of first variable'

Search for another: 'Value of second variable'


G. Ken Holman                    mailto:gkholman@xxxxxxxxxxxxxxxxxxxx
Crane Softwrights Ltd.   
Box 266, Kars, Ontario CANADA K0A-2E0   +1(613)489-0999   (Fax:-0995)
Web site: XSL/XML/DSSSL/SGML services, training, libraries, products.
Practical Transformation Using XSLT and XPath      ISBN 1-894049-02-0
Next instructor-led training:  1999-11-08, 1999-11-09, 1999-12-05/06,
-                1999-12-07, 2000-02-27/28, 2000-05-11/12, 2000-05-15

XSL-List info and archive:


These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.