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 August 7th, 2006, 04:10 PM
Registered User
 
Join Date: Aug 2006
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default formatting phone numbers

I am using (and learning) XSLT 1.0 (which I am limited to for the moment) to solve some "simple" XML -> XML transformations. I have been asked to strip out all non-digits from a phone number field into three fields, <area_code>, <phone>, and <extension>. The input data is entered by humans, so the format varies from document to document. I bought Michael Kay's excellent book "XSLT Programmer's Reference, 2nd ed." some time ago. From this, I am somewhat limited in the string manipulation functions and need to use the translate function. Is there any way to specify more simply what I need to do other than the following?


<xsl:variable name="rawPhone" select="some/path/to/raw/PhoneNumber" />
<xsl:variable name="phoneDigits" select="translate($rawPhone,'0123456789()-./!@#$%*_=+{}[]|;,','0123456789')" />
<area_code><xsl:value-of select="substring($phoneDigits,1,3)"/></area_code>
<phone><xsl:value-of select="substring($phoneDigits,4,7)"/></phone>
<extension><xsl:value-of select="substring($phoneDigits,11)"/></extension>

NOTE: I also include a space as a character to be removed, but it wraps badly on this forum.
I'm not sure of the exact characters that are legal to put in the translate function, but what if the user had entered a '<' or '&'? How would I specify those characters for removal in the translate function?
I was hoping I could use regular expressions or other ways to specify sets of characters.

Any help is appreciated,

A humble XSLT student





Similar Threads
Thread Thread Starter Forum Replies Last Post
Regular expression for phone numbers [both U.S. an kamii47 BOOK: Beginning Regular Expressions 0 September 8th, 2007 03:08 AM
Removing Blank Spaces in Phone Numbers Brendan Bartley Access 1 April 12th, 2007 11:42 AM
Phone # field formatting! Nostromo77 ASP.NET 2.0 Basics 3 December 19th, 2006 02:02 PM
trying to make a custom label for phone numbers... thenoseknows ASP.NET 2.0 Professional 2 August 22nd, 2006 06:07 PM
U.S versus International Phone Numbers bph Access 6 February 19th, 2004 05:15 PM





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