[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

Re: [xsl] one function call twice for the same variable


Subject: Re: [xsl] one function call twice for the same variable
From: Wendell Piez <wapiez@xxxxxxxxxxxxxxxx>
Date: Mon, 10 Jul 2006 16:44:27 -0400

Renate,

At 03:20 PM 7/10/2006, you wrote:
I need to call one function for the same variable twice (somethin like
recursive)...
How to do this?


<xsl:variable name="CustomerSignerLName"> <xsl:call-template name="change"> <xsl:with-param name="name_string" select="LNAME"/> <xsl:with-param name="delimiter" select="'-'"/> </xsl:call-template> </xsl:variable>


And once again with the same parameter:
<xsl:call-template name="change">
<xsl:with-param name="name_string" select="$CustomerSignerLName"/>
<xsl:with-param name="delimiter" select="'-'"/>
</xsl:call-template>


And twice with another parameter:
<xsl:call-template name="change">
<xsl:with-param name="name_string" select="$CustomerSignerLName"/>
<xsl:with-param name="delimiter" select="' '"/>
</xsl:call-template>


<xsl:call-template name="change">
<xsl:with-param name="name_string" select="$CustomerSignerLName"/>
<xsl:with-param name="delimiter" select="' '"/>
</xsl:call-template>


How to write it correctly?

I don't see any obvious syntax errors here, but it's also not clear from your description what you are trying to accomplish.


Oh, I think I get it. Try this:

<xsl:template name="change-string">
<xsl:param name="so-far" select="''"/>
<xsl:param name="delimiter-string" select="'-- '"/>
<xsl:choose>
<xsl:when test="$delimiter-string">
<xsl:call-template name="change-string">
<xsl:with-param name="so-far">
<xsl:call-template name="change">
<xsl:with-param name="name_string" select="$so-far"/>
<xsl:with-param name="delimiter" select="substring($delimiter-string,1,1)"/>
</xsl:call-template>
</xsl:with-param name="delimiter-string"
select="substring($delimiter-string,2)"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$so-far"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>


Pass in $CustomerSignerLname to be the "so-far" value when you call it.

This kind of thing is much nicer in XSLT 2.0, where XPath is stronger and we even have user-defined functions.

Note: wild guess, not checked, tested or refined, comes without warranty.

Cheers,
Wendell


Current Thread
Keywords