Re: [xsl] parametrized return values in recursive functions?

Subject: Re: [xsl] parametrized return values in recursive functions?
From: Mukul Gandhi <gandhi.mukul@xxxxxxxxx>
Date: Fri, 3 Apr 2009 21:00:09 +0530
It would help us to understand the problem, if you could please post a
sample input and the required output.

Are you using XSLT 1.0 or 2.0? Which XSLT processor are you using?

On Fri, Apr 3, 2009 at 5:56 PM, himanshu padmanabhi
<himanshu.padmanabhi@xxxxxxxxx> wrote:
>
> Thanks a ton for all that.
>
> <xsl:template match="Services">
> B  B <xsl:param name="flag" />
> B  B <tr><td>
> B  B  <select name="args1">
>
> <!--
> "$value" will contain '--name servicename1'.
>
> "$args1" will contain list of all service names SEPARATED BY SPACE
> obv. including 'servicename1'.
>
> so this portion will only print 'servicename1' in combo eliminating
> '--name' with help of 'flag' condition.
>
> I want to capture 'servicename1',so that I can pass it to next
> tokenize which print all other service names
>
> from combo index 1 onwards(0th being 'servicename1').Passing parameter
> as 'servicename1' will exclude
>
> it printing twice in this tokenize
> -->
> B B B B B B  B <xsl:if test="$value">
> B B B B B B B B B B B  <xsl:call-template name="str:tokenize">
> B B B B B B B B B B B B B B B B B B  <xsl:with-param name="args"
select="$value" />
> B B B B B B B B B B B B B B B B B B B  <xsl:with-param name="flag"
select="1" />
> B B B B B B B B B B B B  </xsl:call-template>
> B B B B B B B B  </xsl:if>
> B B B B B B B B  <xsl:call-template name="str:tokenize">
> B B B B B B B B B B B B B B B B B  <xsl:with-param name="args"
select="$args1"/>
> B B B B B B B B B B B B B B B B B  <xsl:with-param name="flag" select="0"
/>
> B B B B B B B B  </xsl:call-template>
> B  B  B </select>
> B  B <td><tr>
> </xsl:template>
>
> <!-- string tokenize function -->
> <xsl:template name="str:tokenize">
> B B B  <xsl:param name="args" select="$args" />
> B B B  <xsl:param name="delimiters" select="' '" />
> B B B  <xsl:param name="flag" select="$flag" />
>
> B B B  <xsl:call-template name="str:_tokenize-delimiters">
> B B B B B B B  <xsl:with-param name="args" select="$args" />
> B B B B B B B B B B B  <xsl:with-param name="delimiters"
select="$delimiters" />
> B B B B B B B B B B B  <xsl:with-param name="flag" select="$flag"/>
> B B B  </xsl:call-template>
> </xsl:template>
>
>
> <xsl:template name="str:_tokenize-delimiters">
> B B B  <xsl:param name="args"/>
> B B B  <xsl:param name="delimiters"/>
> B B B  <xsl:param name="pos" select="1"/>
> B B B  <xsl:param name="flag" />
>
> B B B  <xsl:variable name="delimiter" select="substring($delimiters, 1,
1)"/>
>
> B B B  <xsl:variable name="left">
> B B B B B B B  <xsl:choose>
> B B B B B B B B B B B  <xsl:when test="not(contains($args,$delimiter))">
> B B B B B B B B B B B B B B B  <xsl:value-of select="$args"/>
> B B B B B B B B B B B  </xsl:when>
>
> B B B B B B B B B B B  <xsl:otherwise>
> B B B B B B B B B B B B B B B  <xsl:value-of
select="substring-before($args,$delimiter)"/>
> B B B B B B B B B B B  </xsl:otherwise>
> B B B B B B B  </xsl:choose>
> B B B  </xsl:variable>
>
> B B B  <xsl:variable name="right"
select="substring-after($args,$delimiter)"/>
>
> B B B  <xsl:if test="$left != ''">
> B B B B B B B  <xsl:if test="not($flag = 1 and $pos = 1)">
> B B B B B B B B B B B  <option pos="{$pos}"><xsl:value-of
select="$left"/></option>
> B B B B B B B  </xsl:if>
> B B B  </xsl:if>
>
> B B B  <xsl:if test="$right != ''">
> B B B B B B B  <xsl:call-template name="str:_tokenize-delimiters">
> B B B B B B B B B B B  <xsl:with-param name="args" select="$right"/>
> B B B B B B B B B B B  <xsl:with-param name="delimiters"
select="$delimiters"/>
> B B B B B B B B B B B  <xsl:with-param name="pos" select="$pos + 1"/>
> B B B B B B B B B B B  <xsl:with-param name="flag" select="$flag" />
> B B B B B B B  </xsl:call-template>
> B B B  </xsl:if>
> </xsl:template>
>
-----------------------------------------------------------------------------
---------------------------------------
> I tried using
>
> 1.
>
> <xsl:if test="$value">
> B  B  B <xsl:variable name="servname">
> B  B  B  B  B  B <xsl:call-template name="str:tokenize">
> B  B  B  B  B  B  B  B  B  <xsl:with-param name="args" select="$value" />
> B  B  B  B  B  B  B  B  B  B <xsl:with-param name="flag" select="1" />
> B  B  B  B  B  B  </xsl:call-template>
> B  B  </xsl:variable>
> </xsl:if>
> <!-- and passing this variable to next tokenize call which will check
> and wont double print it -->
>
> 2.
> B  B  B  <xsl:call-template name="str:tokenize">
> B  B  B  B  B  B  <xsl:with-param name="args" select="$value" />
> B  B  B  B  B  B  <xsl:with-param name="flag" select="1" />
> B  B  B  B  B  B  <xsl:with-param name="paramreturnvalue" />
> B  B  B  B </xsl:call-template>
>
> B  B <!-- passing this param to every recursive call and filling this
> parameter in the tokenize-delimiter template -->
>
> Both of these approaches didn't worked.
> Can you tell me where I went wrong and which approach is better?
>
> On Thu, Apr 2, 2009 at 1:34 PM, Michael Kay <mike@xxxxxxxxxxxx> wrote:
> >
> > > I just want to ask how to track "position" in recursive
> > > functions like "str:_tokenize-delimiters"?
> >
> > Just give the function another argument, $position, and increment it by
one
> > on each call.
> >
> > Michael Kay
> > http://www.saxonica.com/
> >

> --
> ---------------------------------
> Thanks and Regards,
> Himanshu Padmanabhi



--
Regards,
Mukul Gandhi

Current Thread