Hi Dave,
that should work with a straight
forward xsl:choose statement and the XSL functions number(), string-length() and
substring() to convert your string to a double.
I.e. something like:
<xsl:template name=”StrToNumber”>
<xsl:param
name=”str” />
<xsl:choose>
<xsl:when
test=”starts-with($str, ‘<’) or starts-with($str, ‘>’)”>
<xsl:value-of
select=”number(substring($str, string-length(‘<X’)))”
/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of
select=”number($str)” />
</xsl:otherwise>
</xsl:if>
</xsl:template>
Extensive testing is left
to the reader. J
Cheers,
Dominik
From: Xmplar [mailto:]
Sent: Friday, May 25, 2012 4:39 AM
To: Bob Stayton
Cc: DocBook Apps
Subject: Re: [docbook-apps]
Aligning numbers in table cells with xsl
I managed to (almost) fix the problem by adding a test
for NaN to the string variable:
<xsl:if test="(ancestor-or-self::d:table/@tabstyle = 'numbers' or
ancestor-or-self::d:table/@tabstyle =
'numberstripe') and not(ancestor::d:thead or
ancestor::d:tfoot) and
preceding-sibling::d:entry and (string(number(.) != 'NaN'))">
This however will not select any cells that have a number and a non-numeric string (such as greater
than or less than signs: <1, or >20) - my test treats those cells as a string
and not as a number. I now need to find how to convert < and > to
a number so that the test selects cells with a number and a lt or gt sign.
On 24-05-12 4:24 PM, Bob Stayton wrote:
<xsl:if
test="(ancestor-or-self::d:table/@tabstyle = 'numbers' or
ancestor-or-self::d:table/@tabstyle =
'numberstripe') and not(ancestor::d:thead or
ancestor::d:tfoot) and
preceding-sibling::d:entry and string(number(.))">
--
Dave Gardiner
Xmplar
http://xmplar.biz
Mob. 0416 833 993