This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: RE: creating a string of repeated charactors
- To: timw at 3d3 dot com
- Subject: [xsl] Re: RE: creating a string of repeated charactors
- From: Dimitre Novatchev <dnovatchev at yahoo dot com>
- Date: Mon, 16 Jul 2001 02:03:20 -0700 (PDT)
- Cc: xsl-list at lists dot mulberrytech dot com
- Reply-To: xsl-list at lists dot mulberrytech dot com
Tim Watts wrote:
[snip]
> The EXSLT function <xsl:value-of select="str:padding(10, '*')" /> function
> is the sort of thing I hoped might exist in *standard* XSLT.
>
> Since there isn't I'll use the template that you pointed me to instead.
> (Thanks for saving me from writing it! :) )
>
> I was hoping that there might me a less verbose way of doing what really is
> quite a simple task.
This template is "verbose" by necessity -- it solves the ***general*** case, when
neither the filling characters, nor an upper limit for the length are nown in
advance.
It is also quite space-consuming (and time) -- because the string length is doubled
until a larger string is constructed, this will use twice as much memory, as
necessary for the resulting string.
In many cases one knows in advance that he'll only need a string of upto N
characters.
Then, a much simpler solution is to have a global variable pre-defined, containing
the maximum string:
<xsl:variable name="maxString" select="****************************"/>
and you'll construct any necessary string of length k <= N by simply:
<xsl:variable name="myRepeatingString" select="substring($maxString, 1, $k)"/>
In case you'd need repeating different character patterns at different times, but
still have a clear estimation of the upper limit for the resulting string length,
you can have a separate template, that will accept the character and the length as
parameters and will:
<xsl:variable name-maxString" select="concat($c,$c,$c,$c,$c,$c, ..., $c,$c)"/>
N times ------------------------------------^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
<xsl:value-of select="substring($maxString, 1, $k)"/>
I believe that a sensible implementation of concat() will use less memory (than the
exslt str:padding template requires) in building the above concatenation string.
Cheers,
Dimitre Novatchev.
__________________________________________________
Do You Yahoo!?
Get personalized email addresses from Yahoo! Mail
http://personal.mail.yahoo.com/
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list