This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
RE: creating a string of repeated characters or Padding
- To: "'xsl-list at lists dot mulberrytech dot com'" <xsl-list at lists dot mulberrytech dot com>
- Subject: RE: [xsl] creating a string of repeated characters or Padding
- From: "Lomvardias, Christopher" <clomvardias at syscom dot com>
- Date: Thu, 16 Aug 2001 14:23:13 -0400
- Reply-To: xsl-list at lists dot mulberrytech dot com
Kurt,
Thanks. Though I must admit I'm not clear on how to call the pad template in
my stylesheet.
Chris
-----Original Message-----
From: Kurt Cagle [mailto:cagle@olywa.net]
Sent: Thursday, August 16, 2001 2:14 PM
To: xsl-list@lists.mulberrytech.com
Subject: Re: [xsl] creating a string of repeated characters or Padding
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>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
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list