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

  • Home
  • SEARCH
  • 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 6029795
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T04:56:24+00:00 2026-05-23T04:56:24+00:00

I have an XML file and I’m trying convert it into a (table( HTML

  • 0

I have an XML file and I’m trying convert it into a (table( HTML file.
This is my XML file:

<?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>
<CONTACT>
    <FirstName>ReganPaul</FirstName>
    <LastName>Paul Michael Regan</LastName>
    <URL>http://www.facebook.com/profile.php?id=1660466705</URL>
    <EMAILS/>
</CONTACT>
<CONTACT>
    <FirstName>keyankarthik</FirstName>
    <LastName>karthik keyan</LastName>
    <EMAILS>
        <EMail>
        <Type>yahoo</Type>
        <Value>karthycse@yahoo.co.in</Value>
        </EMail>
    </EMAILS>
</CONTACT>
<CONTACT>
    <FirstName>ColomboGiorgia</FirstName>
    <LastName>Giorgia Colombo</LastName>
    <EMAILS>
        <EMail>
        <Type>libero</Type>
        <Value>giorgiacolombo89@libero.it</Value>
        </EMail>
    </EMAILS>
</CONTACT>
</CONTACTS>

This is my XSL file:

<?xml version="1.0" ?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" >

<!-- / forward slash is used to denote a patern that matches
the root node of the XML      document -->
<xsl:template match ="/" >
<html>
  <head>
    <title> ContactMatrix</title>
  </head>
  <body>
    <xsl:apply-templates />
  </body>
</html>
</xsl:template>

<xsl:template match="CONTACTS" >
<table width="400" border="1" >
    <tr bgcolor = "#546789" >
        <td>FirstName</td>
        <td>LastName</td>
        <td>Gmail</td>
        <td>Yahoo</td>
        <td>Libero</td>
        <td>URL</td>
    </tr>
<xsl:for-each select="CONTACT" >
    <tr>
        <td> <xsl:value-of select="FirstName"/> </td>
        <td> <xsl:value-of select="LastName"/> </td>

 <!-- here we use /@ to access the value of an attribute -->
        <td> <xsl:value-of select="Type/Value=@gmail.com"/> </td>
        <td> <xsl:value-of select="@yahoo.com"/> </td>
        <td> <xsl:value-of select="@libero.it"/> </td>
        <td> <xsl:value-of select="URL"/> </td>
    </tr>
 </xsl:for-each>
 </table>
</xsl:template >
</xsl:stylesheet >

In my html table, the value for gmail,yahoo,libero = False.
This is the sample code in html file for the FirstName:Rangarajkarthik

<tr>
<td>Rangarajkarthik</td><td>karthik Rangaraj</td><td>false</td><td>false</td><td>false</td><td></td>
</tr>

Please assist me.

  • 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-23T04:56:25+00:00Added an answer on May 23, 2026 at 4:56 am

    You are not correctly selecting the element value for the emails. For instance, by the instruction:

    <xsl:value-of select="@yahoo.com"/>
    

    You are asking for selecting a node with name @yahoo.com among the child nodes of CONTACT. You should use:

      <xsl:value-of select="EMAILS/
                    EMail[Type='yahoo']/Value"/>
    

    This instruction gets the text of Value, child of EMail whose Type is ‘yahoo’. The code within the select attribute is just an XPath selection using a predicate [..] to match the wanted element. I really suggest to have a look at W3C tutorial site, and spend some minute on it.

    Your xsl:for-each approach to build a table is not wrong and you are close to a good solution; however a more XSLT way to accomplish that is just using xsl:apply-templates in the correct place.

    <xsl:stylesheet version="1.0"
        xmlns:xsl="http://www.w3.org/1999/XSL/Transform" >
    
        <xsl:output method="html" indent="yes"/>
        <xsl:strip-space elements="*"/> 
    
        <xsl:template match="CONTACTS" >
            <html>
                <head>
                    <title>ContactMatrix</title>
                </head>
                <body>
                    <table width="400" border="1" >
                        <tr bgcolor = "#546789" >
                            <th>FirstName</th>
                            <th>LastName</th>
                            <th>Gmail</th>
                            <th>Yahoo</th>
                            <th>Libero</th>
                            <th>URL</th>
                        </tr>
                        <xsl:apply-templates select="CONTACT"/>
                    </table>
                </body>
            </html>
        </xsl:template>
    
        <xsl:template match="CONTACT">
            <tr>
                <td><xsl:value-of select="FirstName"/> </td>
                <td><xsl:value-of select="LastName"/> </td>
                <td><xsl:value-of select="EMAILS/
                        EMail[Type='gmail']/Value"/>
              </td>
                <td><xsl:value-of select="EMAILS/
                        EMail[Type='yahoo']/Value"/> 
                </td>
                <td><xsl:value-of select="EMAILS/
                        EMail[Type='libero']/Value"/> 
                </td>
                <td><xsl:value-of select="URL"/></td>
            </tr>
        </xsl:template>
    
    </xsl:stylesheet>
    

    When applied to your input, produces:

    <html>
       <head>
          <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    
          <title>ContactMatrix</title>
       </head>
       <body>
          <table width="400" border="1">
             <tr bgcolor="#546789">
                <th>FirstName</th>
                <th>LastName</th>
                <th>Gmail</th>
                <th>Yahoo</th>
                <th>Libero</th>
                <th>URL</th>
             </tr>
             <tr>
                <td>AfgZohal</td>
                <td>Zohal Afg</td>
                <td></td>
                <td></td>
                <td></td>
                <td></td>
             </tr>
             <tr>
                <td>Rangarajkarthik</td>
                <td>karthik Rangaraj</td>
                <td>kart2006@gmail.com</td>
                <td>karthikrangaraj@yahoo.com</td>
                <td></td>
                <td></td>
             </tr>
             <tr>
                <td>ReganPaul</td>
                <td>Paul Michael Regan</td>
                <td></td>
                <td></td>
                <td></td>
                <td>http://www.facebook.com/profile.php?id=1660466705</td>
             </tr>
             <tr>
                <td>keyankarthik</td>
                <td>karthik keyan</td>
                <td></td>
                <td>karthycse@yahoo.co.in</td>
                <td></td>
                <td></td>
             </tr>
             <tr>
                <td>ColomboGiorgia</td>
                <td>Giorgia Colombo</td>
                <td></td>
                <td></td>
                <td>giorgiacolombo89@libero.it</td>
                <td></td>
             </tr>
          </table>
       </body>
    </html>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a XML file like this : <?xml version=1.0 encoding=UTF-8 standalone=no ?> <user>
I have a XML File like that <?xml version=1.0 encoding=utf-8 ?> <Configurations> <EmailConfiguration> <userName>xxxx</userName>
I have xml file whose structure is defined with following xsd: <?xml version=1.0 encoding=utf-8?>
I have a XML file <?xml version=1.0 encoding=UTF-8?> <xml> <events date=12/12/2010> <event> <title>JqueryEvent</title> <description>
i have a XML file as follows: <?xml version=1.0 encoding=utf-8 ?> <publisher> <name>abc</name> <link>http://</link>
What is the easiest way to convert xml to html? I have xml file
I have XML file which looks like this: <?xml version=1.0?> <results> <row id=100><name>name blah</name></row>
I have an XML file that starts like this: <Elements name=Entities xmlns=XS-GenerationToolElements> I'll have
I have an XML file, which I open in F# like this: let Bookmarks(xmlFile:string)
I have an XML file loaded into a DOM document, I wish to iterate

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.