RE: [xsl] Xslt 2 stripping out non-numbers

Subject: RE: [xsl] Xslt 2 stripping out non-numbers
From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx>
Date: Tue, 19 Apr 2005 14:11:32 -0400
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@xxxxxxxxxxxxxxx>
> Sent:     Tue, 19 Apr 2005 13:22:30 -0400
> To:       <xsl-list@xxxxxxxxxxxxxxxxxxxxxx>
> 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@xxxxxxxxxxxxxxxxxxxx
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

Current Thread