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

Questions about XML that are not covered by the other forums should go here.
ronix
Posts: 12
Joined: Wed Oct 31, 2007 1:25 pm

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

Post 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-', '')">
ronix
Posts: 12
Joined: Wed Oct 31, 2007 1:25 pm

Post 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...
sorin_ristache
Posts: 4141
Joined: Fri Mar 28, 2003 2:12 pm

Post 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
jkmyoung
Posts: 89
Joined: Mon Mar 06, 2006 10:13 pm

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