Subject: Re: [xsl] dynamic variable name/implementation question From: "Nathan Young" <natyoung@xxxxxxxxx> Date: Thu, 25 Aug 2005 14:11:16 -0700 |
<xsl:stylesheet> <xsl:param name="p1"/> <xsl:param name="p2"/> <xsl:param name="p3"/> ...
<xsl:template match="external-vaue"> <xsl:choose> <xsl:when test="@parameter = 'someParam'"> <xsl:value-of select="$p1"/> </xsl:when> <xsl:when test="@parameter = 'someOtherParam'"> <xsl:value-of select="$p2"/> </xsl:when> </xsl:choose> </xsl:template>
<xsl:stylesheet> <xsl:param name="language" select="'en'"/> <xsl:param name="country" select="'US'"/> <xsl:param name="dictName"/> <xsl:variable name="dictionary" select="document($dictName)"/>
<xsl:template match="/ | @* | node()"> <xsl:copy> <xsl:apply-templates select="@* | node()"/> </xsl:copy> </xsl:template>
On 8/26/05, Nathan Young <natyoung@xxxxxxxxx> wrote:Hi.
I agree that the nodeset solution offered below is the most flexible
solution (you can pass one in or load one with the document() function).
Parsers differ in the way they handle this; using LibXML with perl I use
the document function but haven't figured out how to pass a DOM as a param.
However, the way you describe passing things in using parameters
constrains you to a fixed set of params defined in your stylesheet so you
could go with a choose block in your template match.
Not at all. The passed nodeset may contain elements with arbitrary names. you get access to whatever parameter you need with something like this:
$pEnvironment[name() = 'myparamName']
In case you don't want the parameter name ('myparamName') fixed in the stylesheet, it itself may be passed as a parameter to the stylesheet.
One way to implement dynamically created variables (such as in a simple calculator) is described here: http://www.mulberrytech.com/Extreme/Proceedings/html/2003/Novatchev01/EML2003Novatchev01.html#t3.6
Cheers, Dimitre Novatchev
Nathan Young A: ncy1717 E: natyoung@xxxxxxxxx
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] dynamic variable name/imp, Dimitre Novatchev | Thread | RE: [xsl] dynamic variable name/imp, Mike Schinkel |
RE: [xsl] dynamic variable name/imp, JBryant | Date | RE: [xsl] Transform XML to XML, Wendell Piez |
Month |