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

Re: How can I simulate a replicate-function in xsl: re

Subject: Re: How can I simulate a replicate-function in xsl: replicate('abc',3) -> 'abcabcabc'
From: "Christopher R. Maden" <crism@xxxxxxxxx>
Date: Thu, 14 Mar 2002 00:29:26 -0800
xsl replicate
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

At 12:12 AM 3/14/02, Rene de Vries wrote:
>Can you tell me how to simulate a replicate-function in xsl:
>replicate('abc',3) -> 'abcabcabc'

You can't do this as a simple function.  You either need an extension 
function or recursive named templates.

If you know the string in advance, you could use a substring:

substring('abcabcabcabcabcabcabcabcabcabcabcabcabc',3*3)

But the named template is the most general solution:

<xsl:call-template name="replicate">
   <xsl:with-param name="string" select="'abc'"/>
   <xsl:with-param name="num" select="3"/>
</xsl:call-template>

<xsl:template name="replicate">
   <xsl:param name="string" select="''"/>
   <xsl:param name="num" select="1"/>
   <xsl:value-of select="$string"/>
   <xsl:if test="$num &gt; 1">
     <xsl:call-template name="replicate">
       <xsl:with-param name="string" select="$string"/>
       <xsl:with-param name="num" select="$num - 1"/>
     </xsl:call-template>
   </xsl:if>
</xsl:template>

~Chris
- -- 
Christopher R. Maden, Principal Consultant, crism consulting
DTDs/schemas - conversion - ebooks - publishing - Web - B2B - training
<URL: http://crism.maden.org/consulting/ >
PGP Fingerprint: BBA6 4085 DED0 E176 D6D4  5DFC AC52 F825 AFEC 58DA
-----BEGIN PGP SIGNATURE-----
Version: PGP Personal Privacy 6.5.8

iQA/AwUBPJBfZqxS+CWv7FjaEQIxIgCg0B5U381uaVhWXpoW9Nhv8nU5yAwAnReE
t0lncbpsjxhfpuyx9RILvKHj
=yJ/Q
-----END PGP SIGNATURE-----


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


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.