Subject: Re: creating a string of repeated characters or Padding
From: "cutlass" <cutlass@xxxxxxxxxxx>
Date: Thu, 16 Aug 2001 19:34:57 +0100
|
use <xsl:call-template>
http://www.dpawson.co.uk/xsl/sect2/N1711.html
cheers, jim
----- Original Message -----
From: "Lomvardias, Christopher" <clomvardias@xxxxxxxxxx>
To: <xsl-list@xxxxxxxxxxxxxxxxxxxxxx>
Sent: Thursday, August 16, 2001 7:23 PM
Subject: RE: creating a string of repeated characters or Padding
> 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@xxxxxxxxx]
> Sent: Thursday, August 16, 2001 2:14 PM
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject: Re: 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
>
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
|