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 January 20th, 2015, 09:17 AM
Registered User
 
Join Date: Jan 2015
Posts: 3
Thanks: 2
Thanked 0 Times in 0 Posts
Exclamation Email and phone regex

Hi All,

I am new to XSLT, Can anyone help and to fetching email id and phone number from the para tag (example mentioned below) and apply the appropriate email and phone tag to the text like this <email>[email protected]</email> <contact>+9998412122</contact> Please see the input and required output

Source:
<para>
This is the para text and this para contains emailid and email id is [email protected] and contact number is +9998412122
</para>

Required Output:
<para>
This is the para text and this para contains emailid and email id is <email>[email protected]</email> and contact number is <contact>+9998412122</contact>
</para>

Last edited by nachi; January 20th, 2015 at 11:00 AM.. Reason: Changes
 
Old January 20th, 2015, 10:26 AM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

What have you tried so far? If it is just the regex you need then googling would be of more help.

Also consider reading the post here: Hints for a good XSLT post
__________________
/- Sam Judson : Wrox Technical Editor -/

Think before you post: What have you tried?
The Following User Says Thank You to samjudson For This Useful Post:
nachi (January 20th, 2015)
 
Old January 20th, 2015, 11:02 AM
Registered User
 
Join Date: Jan 2015
Posts: 3
Thanks: 2
Thanked 0 Times in 0 Posts
Exclamation Fetching specific content and apply tag using XSLT

Quote:
Originally Posted by samjudson View Post
What have you tried so far? If it is just the regex you need then googling would be of more help.

Also consider reading the post here: Hints for a good XSLT post
Thanks for your comment and suggestion, I tried but I will not get the perfect output thats why I came to p2p.
 
Old January 20th, 2015, 11:50 AM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

Strange, I didn't ask IF you had tried, I asked WHAT you had tried...

Could you post examples of what you have tried, and we will try to work out what you are doing wrong (helping you learn).
__________________
/- Sam Judson : Wrox Technical Editor -/

Think before you post: What have you tried?
The Following User Says Thank You to samjudson For This Useful Post:
nachi (January 20th, 2015)
 
Old January 20th, 2015, 02:24 PM
Registered User
 
Join Date: Jan 2015
Posts: 3
Thanks: 2
Thanked 0 Times in 0 Posts
Exclamation XSLT and XML

Quote:
Originally Posted by samjudson View Post
Strange, I didn't ask IF you had tried, I asked WHAT you had tried...

Could you post examples of what you have tried, and we will try to work out what you are doing wrong (helping you learn).
oops, Sorry sam. Here is my example I tried to catch the email and phone number in between paras.

Please check my xslt and xml file below.
----MY XML-----
Code:
<?xml version="1.0" encoding="UTF-8"?>
<companygroup>
<para>This is the example code, this para contains emaid id [email protected] and contact phone is +9199999984521</para>
</companygroup>
----XSLT-----
Code:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output method="xml" indent="no"/>
    <xsl:preserve-space elements="*"/>
   <xsl:template match="@*|node()">
       <xsl:copy>
<xsl:apply-templates/>
       </xsl:copy>
   </xsl:template>
    <xsl:template match="//para">
<!--        [email protected]        +9199999984521 -->
        <xsl:analyze-string select="." regex="\s+(\w*\.\d*_\d*@\w*.*)\s+(\d{{13}})\s?">
         <xsl:matching-substring>
             <email><xsl:value-of select="regex-group(1)"/></email>
             <phone><xsl:value-of select="regex-group(1)"/></phone>
         </xsl:matching-substring>
            <xsl:non-matching-substring>
                <para test="false"><xsl:value-of select="."/></para>   
            </xsl:non-matching-substring>
        </xsl:analyze-string>
    </xsl:template>
</xsl:stylesheet>
My required output should like below
Code:
<?xml version="1.0" encoding="UTF-8"?>
<companygroup>
<para>This is the example code, this para contains emaid id <email>[email protected]</email> and contact phone is <phone>+9199999984521</phone></para>
</companygroup>

Hope I explained my queries...





Similar Threads
Thread Thread Starter Forum Replies Last Post
Phone Gap? vbboyd BOOK: Beginning Android Application Development 1 February 6th, 2012 05:14 AM
phone book nadia_poloei Java Basics 0 January 20th, 2010 05:46 AM
pc to phone priyan.viji ASP.NET 1.x and 2.0 Application Design 0 August 4th, 2007 03:51 AM
Dialing a phone? seananderson Access 2 March 18th, 2007 04:02 AM





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