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

Re: RE: creating a string of repeated charactors

Subject: Re: RE: creating a string of repeated charactors
From: Dimitre Novatchev <dnovatchev@xxxxxxxxx>
Date: Mon, 16 Jul 2001 02:03:20 -0700 (PDT)
the string length is doubled
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


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.