xsl-list
[Top] [All Lists]

Re: variable indirection

2003-12-28 10:26:52

<karim(_at_)ruedesamphis(_dot_)net> wrote in message
news:1072588445(_dot_)3fee669d6e86e(_at_)ssl0(_dot_)ovh(_dot_)net(_dot_)(_dot_)(_dot_)

Hi,

Here's what I want to do :
In a template I've got a variable which value is a string, this string is
also
the name of a variable and I want to access it
For example :
$var1="var2" and I want to get $var2...
Is that possible with xsl?

Generally no.

Exceptions:

  1. A global xsl:variable with *static* content:

          document('')/*/xsl:variable[(_at_)name = $var1]/@select

  2. If the content of your variable is created dynamically, you can express
this with the following dynamically created xml:

     <varContainer:varContainer xmlns:varContainer="my:varContainer">
        <varName1>tree1</varName1>
        <varName2>tree2</varName2>
       .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .
        <varNameN>treeN</varNameN>
     </varContainer:varContainer>

    Then, if the above is the contents of the xsl:variable named
"vContainer", what you want is:

           $vContainer/*[name() = $var1]/node()


There's little meaning in your question as originally formulated, as
typically compiled languages (e.g. C, C++, Java, C#, etc.) do not allow
referencing a variable with dynamically created name.

Some of them have a pre-processor for this, but its work is done even before
compile-time.

Dimitre Novatchev.
FXSL developer

http://fxsl.sourceforge.net/ -- the home of FXSL
Resume: http://fxsl.sf.net/DNovatchev/Resume/Res.html





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



<Prev in Thread] Current Thread [Next in Thread>