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]

Re: Re: creating a string of repeated characters or Padding


If by simple we mean easily understandable, then the following templates/examples
are simple/efficient:

http://www.dpawson.co.uk/xsl/sect2/padding.html (most use known maximum length)

http://sources.redhat.com/ml/xsl-list/2001-07/msg01040.html (efficient in time,
space, recursion depth)


Cheers,
Dimitre Novatchev.

Kurt Cagle wrote:

Chris,

Here's a fairly simple XSLT script that lets you create repeated characters
or padding:

<!-- This stylesheet invokes itself to demonstrate how to use it, but the
only real important part is the named template "pad" below: -->
<?xml-stylesheet type="text/xsl" href="padding.xsl"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform";;
version="1.0">
 <xsl:template match="/">
  <body>
  <!-- For non-whitespace characters, you can call pad directly: -->
  <h1>25 '@' Symbols:</h1>
  <xsl:call-template name="pad">
   <xsl:with-param name="padChar" select="'@'"/>
   <xsl:with-param name="padCount" select="25"/>
  </xsl:call-template>
  <!-- For whitespace characters, things are a little more complicated. Use
a non-whitespace character to generate the content, then pass that into a
temporary variable. Then use the translate() function to map the
non-whitespace character to a white-space one: -->
  <xsl:variable name="pad.tmp"><xsl:call-template name="pad"><xsl:with-param
name="padCount" select="25"/></xsl:call-template></xsl:variable>
  <xsl:variable name="pad" select="translate($pad.tmp,'#',' ')"/>
  <h1>25 Empty Spaces:</h1>
  <pre>.<xsl:value-of select="$pad"/>.</pre><br/>
  </body>
 </xsl:template>

 <xsl:template name="pad">
  <xsl:param name="padChar" select="'#'"/>
     <xsl:param name="padCount" select="0"/><xsl:value-of
select="$padChar"/><xsl:if  test="$padCount&gt;1">
 <xsl:call-template name="pad">
  <xsl:with-param name="padCount" select="number($padCount) - 1"/>
  <xsl:with-param name="padChar" select="$padChar"/>
 </xsl:call-template></xsl:if>
 </xsl:template>
</xsl:stylesheet>

Have fun!

-- Kurt Cagle



__________________________________________________
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


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