|
[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: creating a string of repeated characters or Paddin
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
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|

Cart








