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

Re: one function call twice for the same variable

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

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-2013 All Rights Reserved.