Solved

XSLT

Posted on 2008-10-23
8
621 Views
Last Modified: 2013-11-18
I need XML and XSLT FILES  for formatting a simple US phone number like 517-280-9768 using Regular expressions.

Is there any way to do???Can any one of you send me a sample with any phone number using regular expressions.
I am sure XSLT2.0 supports regular expressions but not sure where to put this line of code and make the example working...
<xsl:analyze:string  select="." regex="([0-9]{{3}})-([0-9]{{4}})">
<xsl:value-of select="regex-group(1)"/>

I would appreicate your help

0
Comment
Question by:onebite2
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
  • 2
8 Comments
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 22790255
If this is your XML

<?xml version="1.0" encoding="UTF-8"?>
<phone>517-280-9768 </phone>

You can use the XSLT attached
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
<xsl:template match="phone">
    <xsl:analyze-string  select="." regex="([0-9]{{3}})-([0-9]{{4}})">
        <xsl:matching-substring>
            <xsl:value-of select="regex-group(1)"/>
        </xsl:matching-substring>
        </xsl:analyze-string>
 </xsl:template>
</xsl:stylesheet>

Open in new window

0
 

Author Comment

by:onebite2
ID: 22790433
I am getting following error:
<xsl:analyze string> is howing a red line with error..

XslTransformException
---------------------
'regex' is not a recognized extension element. An error occurred at C:\Documents and Settings\c-onebite2\My Documents\Visual Studio 2008\Projects\XML File\phone.xslt(8,3).

Can u tell me what should I do....


0
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 22790497
That is because you are using an XSLT1 processor
If you use XSLT2, you have to make sure that you have an XSLT2 processor
I strongly recommend Saxon9B
www.saxonica.com
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 60

Accepted Solution

by:
Geert Bormans earned 500 total points
ID: 22794017
@onebite2,

If you know that the phone number is a correct phone number,
and all you need is the second bit ('280')
This would be an XSLT1 solution for the same problem
(using substring processing since regexes are not available in XSLT1)

@ramuexpert,

I completely miss the point of your post, other then providing a general XSLT1 tutorial (that isn't even very good).
Can you explain how this helps solving this question, before I start reading pages and pages without a clear result.
Please be careful just dumping URLs in responses, you make people loose a lot of time... often for nothing
Thanks

Geert
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
    <xsl:template match="phone">
        <xsl:value-of select="substring-before(substring-after(., '-'), '-')"/>
    </xsl:template>
</xsl:stylesheet>

Open in new window

0
 

Author Comment

by:onebite2
ID: 22796530
@Gertone

Thanks a lot !!Your answer showed me a way.....but I was wondering if I could show the complete phone number instead of just the middle number like 280......
can you tell me what line of code should be added to get the complete number??

If you are going to write xsl:matching-substring implementations using regex to format the string  how about writing a common xsl document which will have all these functions for phone,zip code, date, time, etc. and then link that common file to all our xsl templates.How can we do this???

Thanks a lot !!!I appreciate if you can help me getting a work around for this..
0
 

Expert Comment

by:ramuexpert
ID: 22834886
@Gertone
I am sorry and will take care next time.
My idea is simple if i cannot direct solution , then show some place which might help.
@onebite2:
Were you able to find a fix? Thanks for response.
0
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 22845415
showing the entire phone number is just the <xsl:value-of of the entire element.
   <xsl:template match="phone">
        <xsl:value-of select="."/>
    </xsl:template>

What do you want to do?
It seems that you want to validate wheither a certain field contains a valid phone-number

You can have a general xsl file that contains a number of functions (templates)
and you include that in your XSLT
<xsl:include> is what you need then
0

Featured Post

Containers & Docker to Create a Powerful Team

Containers are an incredibly powerful technology that can provide you and/or your engineering team with huge productivity gains. Using containers, you can deploy, back up, replicate, and move apps and their dependencies quickly and easily.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Preface In the first article: A Better Website Login System (http://www.experts-exchange.com/A_2902.html) I introduced the EE Collaborative Login System and its intended purpose. In this article I will discuss some of the design consideratio…
Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL several years ago, it seemed like now was a good time to update it for object-oriented PHP.  This article does that, replacing as much as possible the pr…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.

696 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question