Solved

XSLT

Posted on 2008-10-23
8
613 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
  • 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
 

Expert Comment

by:ramuexpert
ID: 22791271
0
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

911 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now