[xsl] codepoints-to-string failing on spaces

Subject: [xsl] codepoints-to-string failing on spaces
From: "Spencer Tickner" <spencertickner@xxxxxxxxx>
Date: Wed, 30 Jul 2008 12:06:24 -0700
I calculating character size to get some nice hanging indents in FO.
However my template is failing on spaces and I can't for the life of
me figure out why. I suspected it was codepoints (to or from string)
but when I pull the xPath expressions out of the stylesheet they work
fine. Anyway any advice would be appreciated (processor Saxon 9.0.0.2
that ships with Stylus).

<?xml version='1.0'?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>


    <xsl:variable name="font_table">
        <root>
        <charSet type="Times">
            <char code="32"><name>
</name><wx>250</wx><llx>0</llx><lly>0</lly><urx>0</urx><ury>0</ury></char>
            <char
code="49"><name>1</name><wx>500</wx><llx>111</llx><lly>0</lly><urx>394</urx><ury>676</ury></char>
            <char
code="65"><name>A</name><wx>722</wx><llx>15</llx><lly>0</lly><urx>706</urx><ury>674</ury></char>
		</charSet>
		</root>
	</xsl:variable>

<xsl:template match="/">
	Works -
	<xsl:call-template name="getCharSize">
		<xsl:with-param name="font_size">30</xsl:with-param>
		<xsl:with-param name="text">A1</xsl:with-param>
	</xsl:call-template>

	Doesn't -
	<xsl:call-template name="getCharSize">
		<xsl:with-param name="font_size">30</xsl:with-param>
		<xsl:with-param name="text">A 1</xsl:with-param>
	</xsl:call-template>

</xsl:template>


   <xsl:template name="getCharSize">
        <xsl:param name="text" select="''"/>
        <xsl:param name="font_size" select="0"/>
        <xsl:param name="font_type">Times</xsl:param>
        <xsl:value-of select="
            sum(
                for $i in string-to-codepoints($text) return
                    (
                        $font_size *
                            (
                                number($font_table/root/charSet[@type
= $font_type]/char[name[text() = codepoints-to-string($i)]]/wx)
                            )*0.001
                    )
                )"/>
    </xsl:template>

</xsl:stylesheet>


Thanks,

Spencer

Current Thread