Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6042803
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T06:49:49+00:00 2026-05-23T06:49:49+00:00

I have an xml file and I want to convert into a xml file.

  • 0

I have an xml file and I want to convert into a xml file.

Input XML file:

<?xml version="1.0" encoding="windows-1250"?>
<CONTACTS>
    <CONTACT>
        <FirstName>Arun_niit</FirstName>
        <LastName>Arun_niit</LastName>
        <EMail>nura_ice@yahoo.co.in</EMail>
    </CONTACT>
    <CONTACT>
        <FirstName>FodenBen'</FirstName>
        <LastName>Ben' Foden</LastName>
        <URL>http://www.facebook.com/profile.php?id=100002440474277</URL>
    </CONTACT>
    <CONTACT>
        <FirstName>GhorbelMahmoud</FirstName>
        <LastName>Mahmoud Ghorbel</LastName>
        <EMail>mahmoud.ghorbel@alcatel-lucent.com</EMail>
    </CONTACT>
    <CONTACT>
        <FirstName>keyankarthik</FirstName>
        <LastName>karthik keyan</LastName>
        <EMail>karthycse@yahoo.co.in</EMail>
    </CONTACT>
    <CONTACT>
        <FirstName>Rangarajkarthik</FirstName>
        <LastName>karthik Rangaraj</LastName>
        <EMail>kart2006@gmail.com</EMail>
        <EMail>karthikrangaraj@yahoo.com</EMail>
    </CONTACT>
    <CONTACT>
        <FirstName>ReddyAkky</FirstName>
        <LastName>Akky Reddy</LastName>
        <EMail>akkireddych@gmail.com</EMail>
    </CONTACT>
    <CONTACT>
        <FirstName>SandfordFrankie</FirstName>
        <LastName>Frankie Sandford</LastName>
        <URL>http://www.facebook.com/FrankieSandfordApprovedPage</URL>
    </CONTACT>
    <CONTACT>
        <FirstName>TheSatsRochelle</FirstName>
        <LastName>Rochelle TheSats</LastName>
        <URL>http://www.facebook.com/profile.php?id=100002487211054</URL>
    </CONTACT>
    <CONTACT>
        <FirstName>KumarVeera</FirstName>
        <LastName>Veera_Kumar</LastName>
        <EMail>KUMARg_81@yahoo.com</EMail>
    </CONTACT>
</CONTACTS>

I want the output like this:

        <?xml version="1.0" encoding="UTF-8"?>
<CONTACTS>
<CONTACT>
<PDE-Identity>N65539</PDE-Identity>
<FirstName>Arun_niit</FirstName>
<LastName>Arun_niit</LastName>
<Facebook-ID/>
<Emails>
<Email Type="yahoo" Value="nura_ice@yahoo.co.in"/>
</Emails>
</CONTACT>

<CONTACT>
<PDE-Identity>N65546</PDE-Identity>
<FirstName>FodenBen'</FirstName>
<LastName>Ben' Foden</LastName>
<URL>http://www.facebook.com/profile.php?id=100002440474277</URL>
<Facebook-ID>100002440474277</Facebook-ID>
<EMAILS/>
</CONTACT>

<CONTACT>
<PDE-Identity>N65553</PDE-Identity>
<FirstName>GhorbelMahmoud</FirstName>
<LastName>Mahmoud Ghorbel</LastName>
<Facebook-ID/>
<Emails>
<Email Type="alcatel-lucent" Value="mahmoud.ghorbel@alcatel-lucent.com"/>
</Emails>

<CONTACT>
<PDE-Identity>N65567</PDE-Identity>
<FirstName>Rangarajkarthik</FirstName>
<LastName>karthik Rangaraj</LastName>
<Facebook-ID/>
<Emails>
<Email Type="gmail" Value="kart2006@gmail.com"/>
<Email Type="yahoo" Value="karthikrangaraj@yahoo.com"/>
</Emails>
</CONTACT>

</CONTACTS>

Any idea guys, I have learnt about xslt and i tried to add like this:

This is my xslt file:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output method="xml" indent="yes"/>
    <xsl:strip-space elements="*"/>

    <xsl:template match="node()|@*">
        <xsl:copy>
            <xsl:apply-templates select="node()|@*"/>
        </xsl:copy>
    </xsl:template>

    <xsl:template match="CONTACT">
        <xsl:copy>
               <PDE-Identity>
               <xsl:value-of select="generate-id(.)"/> 
               </PDE-Identity>
              <xsl:copy-of select="FirstName|LastName|URL"/>
              <Facebook-ID><!-- To extract the ID value from URL/Email -->
            <xsl:choose>
                <xsl:when test="URL">
                    <xsl:value-of select="substring-after(URL,'?id=')"/>
                </xsl:when>
                <xsl:otherwise>
                   <!-- <xsl:value-of select="substring-before(EMail[1],'@')"/>-->
                </xsl:otherwise>
            </xsl:choose>
        </Facebook-ID>
            <EMAILS>
                <xsl:apply-templates select="EMail"/>
            </EMAILS>
        </xsl:copy>
    </xsl:template>

    <xsl:template match="EMail">
        <EMail Type="<xsl:value-of select="substring-before(substring-after(.,'@'), '.')"/>" Value="<xsl:value-of select="."/>"/>
    </xsl:template>

</xsl:stylesheet>

It didn’t work. Please help me out guys. Example code; thanks guys.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T06:49:50+00:00Added an answer on May 23, 2026 at 6:49 am
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
        <xsl:output method="xml" indent="yes"/>
        <xsl:strip-space elements="*"/>
    
        <xsl:template match="node()|@*">
            <xsl:copy>
                <xsl:apply-templates select="node()|@*"/>
            </xsl:copy>
        </xsl:template>
    
        <xsl:template match="CONTACT">
            <xsl:copy>
                <xsl:copy-of select="FirstName|LastName"/>
                <EMAILS>
                    <xsl:apply-templates select="EMail"/>
                </EMAILS>
            </xsl:copy>
        </xsl:template>
    
        <xsl:template match="EMail">
            <EMail>
                <type><xsl:value-of select="substring-before(
                        substring-after(.,'@'),
                        '.')"/>
                </type>
                <value><xsl:value-of select="."/></value>
            </EMail>
        </xsl:template>
    
    </xsl:stylesheet>
    

    Given your input, produces:

    <?xml version="1.0" encoding="utf-8"?>
    <CONTACTS>
       <CONTACT>
          <FirstName>AfgZohal</FirstName>
          <LastName>Zohal Afg</LastName>
          <EMAILS/>
       </CONTACT>
       <CONTACT>
          <FirstName>Rangarajkarthik</FirstName>
          <LastName>karthik Rangaraj</LastName>
          <EMAILS>
             <EMail>
                <type>gmail</type>
                <value>kart2006@gmail.com</value>
             </EMail>
             <EMail>
                <type>yahoo</type>
                <value>karthikrangaraj@yahoo.com</value>
             </EMail>
          </EMAILS>
       </CONTACT>
    </CONTACTS>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Imagine I have the folling XML file: <a>before<b>middle</b>after</a> I want to convert it into
I have an XML file which I want to convert into JSON file using
I have a huge xml file and i want to convert it to a
I have the below XML file <?xml version=1.0 encoding=iso-8859-1?> <DATASET> <TYPE>success</TYPE> <RECORD> <DATA type=email>eeee@eee.net</DATA>
I want to write a Object into CSV file. For XML we have XStream
I have an xml file that I want to configure using a bash script.
I have an XML file (on the left) and I want to create multiple
I have an xml data file and I want to populate a listview in
I have a simple xml file and I want to remove everything before the
Let's say I have an empty XML file like so: <root></root> And I want

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.