Re: [xsl] How to robustly handle mutiple condition inputs in Xslt format( Previously Re:Re:How to create variable element from a couple of strings).

Subject: Re: [xsl] How to robustly handle mutiple condition inputs in Xslt format( Previously Re:Re:How to create variable element from a couple of strings).
From: Jeni Tennison <mail@xxxxxxxxxxxxxxxx>
Date: Fri, 25 May 2001 10:50:03 +0100
Hi Sun-Fu,

> May be the best approach I can do is to hard-wire these variables
> which are also pointed by mike brown. So I drive substring-before
> and substring-after function to explicitly list out the variables
> from the given **string*.

What about building an XML structure to hold the values, converting
that to a node set, and then indexing into that when you want to use
the 'variables'?

So something like:

<xsl:template match="/">
   <xsl:variable name="variables-rtf">
      <xsl:call-template name="decompose">
         <xsl:with-param name="s" select="$string"/>
         <xsl:with-param name="nx" select="$vname"/>
      </xsl:call-template>
   </xsl:variable>

   <xsl:variable name="variables"
                 select="msxsl:node-set($variables-rtf)/variable" />

   <xsl:value-of select="$variables[@name = 'x3']" />
   
</xsl:template>

<xsl:template name="decompose">
   <xsl:param name="s" />
   <xsl:param name="nx" />
   <xsl:if test="string($s)" >
      <variable name="{substring-before($nx, ',')}">
         <xsl:value-of select="substring-before($s,',')"/>
      </variable>
      <xsl:call-template name="decompose">
         <xsl:with-param name="s" select="substring-after($s,',')"/>
         <xsl:with-param name="nx" select="substring-after($nx,',')"/>
      </xsl:call-template>
   </xsl:if>
</xsl:template>

Although if you're calling it from Javascript, you could always pass
in $variables directly as a parameter (you can have an RTF parameter
if you use Javascript to access MSXML).

I hope that helps,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/



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


Current Thread