[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

parametrized return values in recursive functions?

Subject: parametrized return values in recursive functions?
From: himanshu padmanabhi <himanshu.padmanabhi@xxxxxxxxx>
Date: Fri, 3 Apr 2009 17:56:53 +0530
 parametrized return values in recursive functions?
Thanks a ton for all that.

<xsl:template match="Services">
    <xsl:param name="flag" />
    <tr><td>
     <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
-->
        <xsl:if test="$value">
            <xsl:call-template name="str:tokenize">
                   <xsl:with-param name="args" select="$value" />
                    <xsl:with-param name="flag" select="1" />
             </xsl:call-template>
         </xsl:if>
         <xsl:call-template name="str:tokenize">
                  <xsl:with-param name="args" select="$args1"/>
                  <xsl:with-param name="flag" select="0" />
         </xsl:call-template>
     </select>
    <td><tr>
</xsl:template>

<!-- string tokenize function -->
<xsl:template name="str:tokenize">
    <xsl:param name="args" select="$args" />
    <xsl:param name="delimiters" select="' '" />
    <xsl:param name="flag" select="$flag" />

    <xsl:call-template name="str:_tokenize-delimiters">
        <xsl:with-param name="args" select="$args" />
            <xsl:with-param name="delimiters" select="$delimiters" />
            <xsl:with-param name="flag" select="$flag"/>
    </xsl:call-template>
</xsl:template>


<xsl:template name="str:_tokenize-delimiters">
    <xsl:param name="args"/>
    <xsl:param name="delimiters"/>
    <xsl:param name="pos" select="1"/>
    <xsl:param name="flag" />

    <xsl:variable name="delimiter" select="substring($delimiters, 1, 1)"/>

    <xsl:variable name="left">
        <xsl:choose>
            <xsl:when test="not(contains($args,$delimiter))">
                <xsl:value-of select="$args"/>
            </xsl:when>

            <xsl:otherwise>
                <xsl:value-of select="substring-before($args,$delimiter)"/>
            </xsl:otherwise>
        </xsl:choose>
    </xsl:variable>

    <xsl:variable name="right" select="substring-after($args,$delimiter)"/>

    <xsl:if test="$left != ''">
        <xsl:if test="not($flag = 1 and $pos = 1)">
            <option pos="{$pos}"><xsl:value-of select="$left"/></option>
        </xsl:if>
    </xsl:if>

    <xsl:if test="$right != ''">
        <xsl:call-template name="str:_tokenize-delimiters">
            <xsl:with-param name="args" select="$right"/>
            <xsl:with-param name="delimiters" select="$delimiters"/>
            <xsl:with-param name="pos" select="$pos + 1"/>
            <xsl:with-param name="flag" select="$flag" />
        </xsl:call-template>
    </xsl:if>
</xsl:template>
-----------------------------------------------------------------------------
---------------------------------------
I tried using

1.

<xsl:if test="$value">
      <xsl:variable name="servname">
            <xsl:call-template name="str:tokenize">
                   <xsl:with-param name="args" select="$value" />
                    <xsl:with-param name="flag" select="1" />
             </xsl:call-template>
     </xsl:variable>
</xsl:if>
<!-- and passing this variable to next tokenize call which will check
and wont double print it -->

2.
       <xsl:call-template name="str:tokenize">
             <xsl:with-param name="args" select="$value" />
             <xsl:with-param name="flag" select="1" />
             <xsl:with-param name="paramreturnvalue" />
        </xsl:call-template>

    <!-- 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

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2007 All Rights Reserved.