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

RE: Variable names *as* variables

Subject: RE: Variable names *as* variables
From: "Meltsner, Kenneth" <Kenneth.Meltsner@xxxxxx>
Date: Thu, 12 Oct 2000 13:51:52 -0400
xsl variable name lists
You could use an association list-like trick

<xsl:variable name="location-list">'location1Miami/location2New York/location3Schenectady'</xsl:variable>

<xsl:value-of select="substring-before(substring-after ($1, @place) , '/')" />

Warning:

Hand-typed.  Did not check.

Ken

-----Original Message-----
From: John E. Simpson [mailto:simpson@xxxxxxxxxxx]
Sent: Thursday, October 12, 2000 11:23 AM
To: xsl-list@xxxxxxxxxxxxxxxx
Subject: Variable names *as* variables


I have a feeling that what I'm trying to do can't be done without 
extensions, like Saxon's eval. Unfortunately I can't use an extension 
function for this case, and thought I'd fly it past the list to see if any 
of you have a brainstorm.

Sample XML:
<someroot>
   <event date="2000-10-11">
     <locale place="location1"/>
     <locale place="location2"/>
     <locale place="location3"/>
   </even>
   <event date="2000-10_12">
     <locale place="location1"/>
     <locale place="location3"/>
   </even>
</someroot>

If I want to display literal text (e.g. "Midtown" for place="location1"), I 
could of course use an xsl:choose block, with an xsl:when for each of the 
valid values of the place attribute. What I'd like to do instead (for 
maintainability, whatever) is set up global variables to be used in place 
of the values of the place attributes. Something like:

<xsl:variable name="location1">Midtown</xsl:variable>
<xsl:variable name="location2">Greater Northeast</xsl:variable>
<xsl:variable name="location3">Dallas-Ft. Worth</xsl:variable>

Then in the template (so goes the theory) I'd just need to do something like:

   <xsl:value-of select="concat('$', @place)"/>

But -- duh -- all this does is produce the *string* "$location1," 
"$location2," and "$location3."

Any ideas? Can't be done with straight XSLT, right?
===============================================================
John E. Simpson               | "He asked me if I knew what
http://www.flixml.org         | time it was. I said, 'Yes, but
XML Q&A: http://www.xml.com   | not right now.'" (Steven Wright) 


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

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.
Email
First Name
Last Name
Company
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.