|
[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] RE: Fixed-length String Output
>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
|
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








