[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: Paul Tchistopolskii <paul@xxxxxxx>
Date: Thu, 12 Oct 2000 20:13:16 -0700
concatenate variable names
----- Original Message ----- 
From: John E. Simpson <simpson@xxxxxxxxxxx>

1. Yes, to make your solution work you need saxon:evaluate.

2. What you really want is a lookup, right? So a bit 'softer' solution 
is to do that with node-set extension function ( which is supported
by many engines, but is still *not* W3C standard. This node-set
is a rudiment of mythical "Result Tree Fragment is not a node-set".

<xsl:stylesheet 
 xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
        xmlns:xt="http://www.jclark.com/xt"
 version="1.0">

<xsl:variable name="loc">location1</xsl:variable>

<xsl:variable name="lookup">
<location1> some thing 1 </location1>
<location2> some thing 2 </location2>
</xsl:variable>

<xsl:template match="/">

<xsl:value-of select="xt:node-set($lookup)/node()[name()=$loc]"/>

</xsl:template>

</xsl:stylesheet>


3. Plain and 100% conformant XSLT solution requires placing 
the lookup  

<location1> some thing 1 </location1>
<location2> some thing 2 </location2>

into standalone XML document and then reading this lookup into 
the variable with document() ( the document provides the nodeset, 
so you don't need xt:node-set conversion ).

Rgds.Paul.


> 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?



 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.