This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: How can I simulate a replicate-function in xsl: replicate('abc',3) -> 'abcabcabc'



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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]