This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: using format-number() for aligned text output


At 01/03/28 14:59 +0800, ericmacau@china.com wrote:
>Is it possible to define the Alignment of a Text/Number in XSLT ?

Not for text, but I had assumed one could for number.  I've shown below a 
trick for doing text alignment.

But ... I think my test has revealed another facet of format-number() that 
is open for interpretation.

I was anticipating format-number(price,'####0.00') to always produce a 
string of 8 characters in length, yet both processors I have (XT and Saxon) 
are Java based and are using the Java library which is known to have other 
problems for this function.

Any alternative interpretations out there for the specification wording of: 
"digit specifies the character used for a digit in the format pattern; the 
default value is the number sign character (#)"?  Would anyone else expect 
the "#" to produce a space if no digit is there?  If that isn't the 
behaviour, then what is the utility of the "#"?

............................... Ken

T:\ftemp>type eric.xml
<items>
<item>
<name>Pen</name>
<price>1.25</price>
</item>
<item>
<name>Pencil</name>
<price>0.5</price>
</item>
<item>
<name>Bag</name>
<price>12.38</price>
</item>
</items>
T:\ftemp>type eric.xsl
<?xml version="1.0"?><!--filename.xsl-->
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
                 version="1.0">

<xsl:variable name="pad" select="'              '"/>
<xsl:variable name="pad-len" select="string-length($pad)"/>

<xsl:template match="/">
   <xsl:for-each select="//item">
     <xsl:value-of select="name"/>
     <xsl:value-of select="substring($pad,1,$pad-len - string-length(name))"/>
     <xsl:text>|</xsl:text>
     <xsl:value-of select="format-number(price,'####0.00')"/>
     <xsl:text>
</xsl:text>
   </xsl:for-each>
</xsl:template>

</xsl:stylesheet>

T:\ftemp>xt eric.xml eric.xsl
<?xml version="1.0" encoding="utf-8"?>
Pen           |1.25
Pencil        |0.50
Bag           |12.38

T:\ftemp>


--
G. Ken Holman                      mailto:gkholman@CraneSoftwrights.com
Crane Softwrights Ltd.               http://www.CraneSoftwrights.com/s/
Box 266, Kars, Ontario CANADA K0A-2E0     +1(613)489-0999   (Fax:-0995)
Web site:     XSL/XML/DSSSL/SGML/OmniMark services, training, products.
Book:  Practical Transformation Using XSLT and XPath ISBN 1-894049-06-3
Article: What is XSLT? http://www.xml.com/pub/2000/08/holman/index.html
Next public instructor-led training:  2001-04-06,2001-05-01,2001-05-14,
-               2001-05-15,2001-05-16,2001-05-17,2001-05-21,2001-05-22,
-                2001-06-18,2001-06-21,2001-07-20,2001-07-21,2001-09-19

!!Five-day XSLT/XPath/XSLFO Training Blitz June 18-22, 2001 in Ottawa!!


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]