You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@xalan.apache.org by Philip Strube <Ph...@ofd.mf.lsa-net.de> on 2000/11/27 16:48:11 UTC
bug-report: round(1.234) is 1234?
round(1.234) should be 1 instead of 1234, right?
Following files deliver (xalan 1.2.1, 1.2.D01, 2.0.D01)
<?xml version="1.0" encoding="UTF-8"?>
<zahlen>
<zahl>1.234pt</zahl>
<points>1.234</points>
<number-points>1234</number-points> *wrong!*
<round-points>1234</round-points> *wrong!*
</zahlen>
and (xalan 1.1.D01)
<?xml version="1.0" encoding="UTF-8"?>
<zahlen>
<zahl>1.234pt</zahl>
<points>1,234</points>
<number-points>1,234</number-points>
<round-points>1</round-points> *right*
</zahlen>
INPUT-FILE:
<?xml version="1.0" encoding="ISO-8859-1"?>
<zahlen>
<zahl>1.234pt</zahl>
</zahlen>
XSLT-FILE:
<?xsl version='1.0' encoding="ISO-8859-1"?>
<xsl:stylesheet xmlns:xsl='http://www.w3.org/1999/XSL/Transform'
version='1.0'>
<xsl:output indent="yes"/>
<xsl:template match="/">
<zahlen>
<xsl:apply-templates select="zahlen/zahl" />
</zahlen>
</xsl:template>
<xsl:template match="zahl">
<zahl>
<xsl:value-of select="."/>
</zahl>
<xsl:variable name="points">
<xsl:call-template name="unitsToPt">
<xsl:with-param name="units" select="."/>
</xsl:call-template>
</xsl:variable>
<points><xsl:value-of select="$points"/></points>
<number-points><xsl:value-of
select="number($points)"/></number-points>
<round-points><xsl:value-of select="round($points)"/></round-points>
</xsl:template>
<xsl:template name="unitsToPt">
<xsl:param name="units"/>
<xsl:variable name="unitsPt">
<xsl:choose>
<xsl:when test="contains($units,'inch')">
<xsl:value-of
select="number(number(substring-before($units,'inch')) *
number('72'))"/>
</xsl:when>
<xsl:when test="contains($units,'pt')">
<xsl:value-of select="number(substring-before($units,'pt'))"/>
</xsl:when>
<xsl:when test="contains($units,'cm')">
<xsl:value-of
select="number(number(substring-before($units,'cm')) *
number('28.3527'))"/>
</xsl:when>
<xsl:otherwise>
<xsl:message terminate='yes'>Unknown number format <xsl:value-of
select="$units"/>
</xsl:message>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:value-of select="$unitsPt"/>
</xsl:template>
</xsl:stylesheet>