Subject: RE: [xsl] concat variable names From: "David N Bertoni/Cambridge/IBM" <david_n_bertoni@xxxxxxxxxx> Date: Thu, 14 Mar 2002 17:55:53 -0800 |
If the values are static, you don't need to use a result tree fragment variable and a proprietary extension: <?xml version="1.0"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:vars ="http://foo.com" version="1.0"> <vars:Settings> <Setting Name="var_1">value_of_var1</Setting> <Setting Name="var_2">value_of_var2</Setting> <Setting Name="var_3">value_of_var3</Setting> <Setting Name="var_4">value_of_var4</Setting> </vars:Settings> <xsl:variable name="mySettings" select="document('')/*/vars:Settings"/> <xsl:template match="/"> <out> <xsl:for-each select="$mySettings/Setting[@Name='var_1']"> ... </xsl:for-each> </out> </xsl:template> </xsl:stylesheet> If you don't want to embed the "variables" in the stylesheet, you can put them in another xml file and load that with the document() function. If you want to compute the values at run-time, then you'll probably need to create a temporary tree, and will then need a "node-set" extension. Dave |---------+-------------------------------------> | | "Dion Houston" | | | <dionh@xxxxxxxxxxxxx> | | | Sent by: | | | owner-xsl-list@xxxxxxxxxxx| | | rrytech.com | | | | | | | | | 03/14/2002 04:50 PM | | | Please respond to xsl-list| | | | |---------+-------------------------------------> >----------------------------------------------------------------------------------------------------------| | | | To: <xsl-list@xxxxxxxxxxxxxxxxxxxxxx> | | cc: (bcc: David N Bertoni/Cambridge/IBM) | | Subject: RE: [xsl] concat variable names | >----------------------------------------------------------------------------------------------------------| Hi Michael: Variable names are constant, so you can't create them dynamically in the way you describe. I would recommend something like this: <xsl:variable name="mySettings.tf"> <Setting Name="var_1">value_of_var1</Setting> <Setting Name="var_2">value_of_var2</Setting> <Setting Name="var_3">value_of_var3</Setting> <Setting Name="var_4">value_of_var4</Setting> </xsl:variable> <xsl:variable name="mySettings" select="msxsl:node-set($mySettings.tf)"/> (replace msxl:node-set() with your preferred nodeset from tree fragment function) You can then replace references to $var_x with $mySettings/Setting[@Name='var_1'], and to get all the values, simply get all $mySettings/Setting. HTH! Dion -----Original Message----- From: Michael Auth [mailto:michael.auth@xxxxxx] Sent: Thursday, March 14, 2002 4:24 PM To: XSL-List@xxxxxxxxxxxxxxxxxxxxxx Subject: [xsl] concat variable names Is there a way to concat the name of a variable? I have 5 variables $var_1, $var_2, ..., $var_5; all declared as global variables. I want to use this varibles in a loop, something like this: loop (count from 1 to 5, store the counter in a variable called $counter) <xsl:variable name="newvar" select="$(concat('var_', $counter))"/> What I want to get, is that the variable $newvar stores the value of $var_1 and in the next run the value of $var2, and so on up to $var_5. It does not work (of course) with the method above, but is there a way it will work??? (It seems to me that this is a general problem in XSL, for I have other projects where it would be very usefully too). Thanks! XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
RE: [xsl] concat variable names, Michael Kay | Thread | [xsl] Problem with image, Alvaro Mujica |
Re: [xsl] insert one PDF file into , David B. Bitton | Date | Re: [xsl] dealing with languages, naha |
Month |