Subject: Re: [xsl] 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 |
-----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 > 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 |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] How can I simulate a replicat, Rene de Vries | Thread | Re: [xsl] How can I simulate a repl, Joerg Heinicke |
Re: [xsl] XSL code for CALS (Oasis), Christopher R. Maden | Date | [xsl] Re: How can I simulate a repl, Dimitre Novatchev |
Month |