This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
RE: Fixed-length String Output
- To: "'xsl-list at mulberrytech dot com'" <xsl-list at mulberrytech dot com>
- Subject: RE: Fixed-length String Output
- From: "DuCharme, Robert" <Robert dot DuCharme at moodys dot com>
- Date: Wed, 4 Oct 2000 14:36:14 -0400
- Reply-To: xsl-list at mulberrytech dot com
>Something like
><xsl:value-of select="substring(concat($string, ' '), 1, 12))"/>
Just as a challenge, I took it a little further. The following outputs the
color values in this document
<test>
<color>red</color>
<color>blue</color>
<color>yellow</color>
</test>
at 12 characters each, right aligned:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:variable name="fieldWidth">12</xsl:variable>
<xsl:template match="color">
<xsl:variable name="valueLength"
select="string-length(normalize-space(.))"/>
<xsl:variable name="padding"
select="$fieldWidth - $valueLength"/>
<xsl:text>[</xsl:text>
<xsl:value-of select="substring(' ',1,$padding)"/>
<xsl:value-of select="."/>
<xsl:text>]</xsl:text>
</xsl:template>
</xsl:stylesheet>
giving this output:
<?xml version="1.0" encoding="utf-8"?>
[ red]
[ blue]
[ yellow]
I'm starting to like local variables more!
Bob DuCharme www.snee.com/bob <bob@
snee.com> "The elements be kind to thee, and make thy
spirits all of comfort!" Anthony and Cleopatra, III ii
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list