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 6894981
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T06:51:02+00:00 2026-05-27T06:51:02+00:00

I have an XML file with certain data which I have to convert it

  • 0

I have an XML file with certain data which I have to convert it into HTML Table. There are 3-4 table with only 2 columns and 4-5 tables with more columns. I want to pass XML attribute value, say tableWidth=200 or tableWidth=500 depending upon the number of columns.

Sample XML File –

<tab>
  <!-- b="Y" will be used if Heading is required -->
  <r b="Y">
    <d>Name</d>
    <d>Age</d>
  </r>
  <r>
    <d>ABC</d>
    <d>23</d>
  </r>
</tab>

Following is the XSLT File –

<xsl:stylesheet version='1.0' xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>
<xsl:output method='html' media-type='text/html'/>
<xsl:template match="Tab">
<table width="500" cellpadding="6" cellspacing="0" align="center">
  <xsl:for-each select="R">
<tr>
    <xsl:choose>
        <xsl:when test="@b = 'Y'">
            <xsl:for-each select="D">
                <td align='' style='border:1px solid black'> 
                    <b><xsl:value-of select="."/></b>
                </td>
            </xsl:for-each>
        </xsl:when>
        <xsl:otherwise>
            <xsl:for-each select="D">
                <td align='' style='border:1px solid black'> 
                    <xsl:value-of select="."/>  
                </td>
            </xsl:for-each>
        </xsl:otherwise>
    </xsl:choose>
</tr>
  </xsl:for-each>
 </table>
 </xsl:template>
 </xsl:stylesheet>   

I want to add an attribute say tablewidth to XML file and use it in the <table> tag is XSLT file…

  • 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-27T06:51:03+00:00Added an answer on May 27, 2026 at 6:51 am

    Assuming you have amended your XML to include an tableWidth attribute, like so…

    <tab tableWidth="500">
        ....
    

    There are two ways to make use of the attribute in the XSLT. Firstly, the more verbose way….

    <xsl:template match="Tab">
       <table cellpadding="6" cellspacing="0" align="center"> 
          <xsl:attribute name="width"><xsl:value-of select="@tableWidth" /></xsl:attribute>
    

    But it is often much cleaner to use Attribute Value Templates. Then you only have to do this:

    <xsl:template match="Tab">
       <table width="{@tableWidth}" cellpadding="6" cellspacing="0" align="center"> 
    

    Both of these should output the following:

    <table width="500" cellpadding="6" cellspacing="0" align="center">
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an XML file in which I want to extract data from certain
What is the easiest way to convert xml to html? I have xml file
I have a table with a few relational columns and one XML column which
Do developers have to put certain/extra elements in the feed's XML file or attributes
I have an xml file providing data for a datagrid in Flex 2 that
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
i need to pull data out of an xml file based on certain field
I am trying to access certain pieces of data from an xml file, here
I have an XML file that has certain properties and mappings defined in it.

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.