Subject: Re: [xsl] creating a string of repeated characters or Padding From: "Kurt Cagle" <cagle@xxxxxxxxx> Date: Thu, 16 Aug 2001 11:13:48 -0700 |
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
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] creating a string of repe, Jeni Tennison | Thread | Re: RE: [xsl] creating a string of , Dimitre Novatchev |
Re: RE: [xsl] creating a string of , Dimitre Novatchev | Date | [xsl] Re: Best way to include code , Mark Galbreath |
Month |