Page 1 of 1

XSL/XPATH compose string and use it as a variable name

Posted: Wed Oct 31, 2007 1:45 pm
by ronix
Hi guys,

there is something i needed many times. Is it possible to compose a string and use it to call an existing variable. XPath allways see only the string.

Code: Select all


<xsl:variable name="page-width-1">
<xsl:variable name="page-width-2">
...
<xsl:variable name="page-width-n">
The the call:

Code: Select all


<xsl:variable name="result" 
select="for $tab in $schr-tabs

<xsl:value-of select="concat('$', 'page-width-', '')">

Posted: Wed Oct 31, 2007 1:58 pm
by ronix
second try :-)

Code: Select all


<xsl:variable name="page-width-1">
<xsl:variable name="page-width-2">
...
<xsl:variable name="page-width-n">
The call can be something like that:

Code: Select all


<xsl:variable name="result" 
select="for $i in 1 to n
return concat('$', 'page-width-', '$i')">
or just

Code: Select all


<xsl:value-of select="concat('$', 'page-width-', '2')">
But this calls even don't work...

Posted: Wed Oct 31, 2007 5:17 pm
by sorin_ristache
Hello,

No, you cannot set a variable name dynamically in XSLT. You should use one variable and compose the value based on a condition.


Regards,
Sorin

Posted: Wed Oct 31, 2007 9:48 pm
by jkmyoung
It may be possible to achieve what you're trying to do using a different method. Are your variables static, or obtained from fields in the source xml?