Subject: Re: Variable names *as* variables From: Paul Tchistopolskii <paul@xxxxxxx> Date: Thu, 12 Oct 2000 20:13:16 -0700 |
----- 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 |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: Variable names *as* variables, Nikolai Grigoriev | Thread | RE: Variable names *as* variables, Meltsner, Kenneth |
RE: Concatenate element values base, Eliot, Topher | Date | RE: SAX or DOM for XSLT, Joshua Allen |
Month |