xsl-list
[Top] [All Lists]

RE: Xslt 2 stripping out non-numbers

2005-04-19 11:11:32
At 2005-04-19 13:53 -0400, Jim Neff wrote:
The characters to be removed could be anything, upper, lower, hyphens,
spaces ... Anything NaN.
...
> -----Original Message-----
> From:     Jim Neff <jneff(_at_)blockvision(_dot_)com>
> Sent:     Tue, 19 Apr 2005 13:22:30 -0400
> To:       <xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com>
> Subject:  [xsl] Xslt 2 stripping out non-numbers
>
> Greetings,
>
> I need to strip out non-numerical values from a string.
>
> Here is a sample input value:  TUV0062
>
> And what I want is :  0062  (or just 62)
...
> What is the correct way to do this using XSLT 2?

Would an XSLT 1 compatible method be acceptable?

I hope the below helps.

. . . . . . . Ken

t:\ftemp>type neff.xsl
<?xml version="1.0" encoding="iso-8859-1"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
                version="1.0">

<xsl:output method="text"/>

<xsl:template match="/">
   <xsl:variable name="target" select="'TUV0062'"/>

   <xsl:value-of select="number(
                          translate($target,
                           translate($target,'0123456789',''),''))"/>
</xsl:template>

</xsl:stylesheet>
t:\ftemp>saxon neff.xsl neff.xsl
62
t:\ftemp>

--
World-wide on-site corporate, govt. & user group XML/XSL training.
G. Ken Holman                 mailto:gkholman(_at_)CraneSoftwrights(_dot_)com
Crane Softwrights Ltd.          http://www.CraneSoftwrights.com/s/
Box 266, Kars, Ontario CANADA K0A-2E0    +1(613)489-0999 (F:-0995)
Male Breast Cancer Awareness  http://www.CraneSoftwrights.com/s/bc
Legal business disclaimers:  http://www.CraneSoftwrights.com/legal


--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--