Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 15th, 2009, 12:01 PM
Authorized User
 
Join Date: Sep 2009
Posts: 14
Thanks: 6
Thanked 0 Times in 0 Posts
Default Remove non-number parts of string

I have one element that should only contain numbers. Occassionaly, however users input dashes and other characters. How can I remove any characters that are not numbers.? Also the first character must be a number. THanks.

12-13 --> 12

12 - 13 --> 12

12,13 --> 12

n/a --> NULL
 
Old October 15th, 2009, 12:09 PM
Friend of Wrox
 
Join Date: Nov 2007
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
Default

Do you use XSLT 2.0 or 1.0? With 2.0 you have regular expressions and the replace function http://www.w3.org/TR/xpath-functions/#func-replace to solve such problems.
__________________
Martin Honnen
Microsoft MVP (XML, Data Platform Development) 2005/04 - 2013/03
My blog
 
Old October 15th, 2009, 12:13 PM
Authorized User
 
Join Date: Sep 2009
Posts: 14
Thanks: 6
Thanked 0 Times in 0 Posts
Default 1.0

We are using 1.0.
 
Old October 15th, 2009, 12:22 PM
Friend of Wrox
 
Join Date: Nov 2007
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
Default

In that case, do you know whether your XSLT 1.0 processor supports extension functions like http://www.exslt.org/regexp/index.html?
__________________
Martin Honnen
Microsoft MVP (XML, Data Platform Development) 2005/04 - 2013/03
My blog
 
Old October 15th, 2009, 12:59 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

There's a neat solution that works in 1.0:

translate($input, translate($input, '0123456789', ''), '')

The inner translate returns all characters present in the string that are not digits; the outer translate removes these characters from the string.
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference





Similar Threads
Thread Thread Starter Forum Replies Last Post
remove commas and space in a string kumiko Classic ASP Basics 1 January 10th, 2008 11:42 PM
Remove the unwanted space at end of the string gmbalaa General .NET 2 August 21st, 2007 11:35 PM
Separating parts of a string and assigning them to anubandh ASP.NET 1.0 and 1.1 Basics 1 May 12th, 2006 12:47 PM
how to replace a string with another string/number crmpicco Javascript How-To 4 March 14th, 2005 12:59 PM
Replace or remove the last char from the string sabu21s XSLT 12 January 8th, 2004 05:26 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.