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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T03:25:14+00:00 2026-06-16T03:25:14+00:00

I’m trying to create a table using XSL/XML. I’m new to XSL and XML,

  • 0

I’m trying to create a table using XSL/XML. I’m new to XSL and XML, so go easy on me please
I’m having a bit of trouble with a few things.
This is my XML file:

<List>
<Classification>
    <Class>
        <Label>Milk</Label>
        <NumberZone>1</NumberZone>

        <Zone>
            <Label>Milk1</Label>
            <Frontier>500</Frontier>
        </Zone>

        <Zone>
            <Label>Milk2</Label>
            <Frontier>600</Frontier>
        </Zone>

        <Zone>
            <Label>Milk3</Label>
            <Frontier>600</Frontier>
        </Zone>

        <Zone>
            <Label>Milk4</Label>
            <Frontier>700</Frontier>
        </Zone>

        <image>
            <File>milk.jpg</File>
        </image>
    </Class>

    <Class>
        <Label>Water</Label>
        <NumberZone>2</NumberZone>

        <Zone>
            <Label>Water1</Label>
            <Frontier>800</Frontier>
        </Zone>

        <Zone>
            <Label>Water2</Label>
            <Frontier>900</Frontier>
        </Zone>

        <image>
            <File>water.jpg</File>
        </image>
    </Class>

    <Class>
        <Label>Juice</Label>
        <NumberZone>3</NumberZone>

        <Zone>
            <Label>Juice1</Label>
            <Frontier>950</Frontier>
        </Zone>

        <Zone>
            <Label>Juice2</Label>
            <Frontier>990</Frontier>
        </Zone>

        <image>
            <File>juice.jpg</File>
        </image>
    </Class>

</Classification>
</List>

It normally is longer, but I cut out some parts.

I want my table to look like this:

  • First column: Milk, Water, Juice…
  • Second column: I want the images.
  • Third column: Milk1, Water1, Juice1.
  • Fourth column: Milk2, Water2, Juice2.
  • (And so on).

So far I have this:

<table border="1">

 <tr><th>Column 1</th><th>Image</th><th>Column 3</th></tr>


        <xsl:for-each select="Classification/Class">
        <tr>
            <td><em><xsl:value-of select="Label" /></em></td>

            <td>
            <xsl:attribute name="src">
            <xsl:value-of select="image/File"/>
            </xsl:attribute>
            </td>

            <td><xsl:value-of select="Zone/Label"/></td>
            <td colspan="1"><xsl:value-of select="Zone/Label"/></td>
            <td colspan="1"><xsl:value-of select="Zone/Label"/></td>
            </tr>
        </xsl:for-each>
</table>
  • This displays the first column perfectly with Milk, Water, and Juice.
  • The second column doesn’t work, it’s just blank. The image won’t appear in the table, any idea on how to fix this?*
  • The third column also works perfectly showing Milk1, Water1, Juice1.
  • The fourth column doesn’t work, obviously, because I’m using the same value-of as in the third column. I don’t know how to get Milk2, Water2, and Juice2 to show in that column, since it uses the same element name (being Zone/Label)

So there’s two thing I need to fix: I need to fix the second column to actually show the image in each boxes.
I also need to fix the fourth column to show Milk2, Water2, and Juice2.
My main problem for now is to get the fourth column to work, I really don’t understand how to display Milk2, Water2, etc.

I would also like to add either radio buttons, or check boxes later on in each cell, so I could use JavaScript in my web page. I feel like each box would need a different ID, so I’m not sure how to achieve that using XSL, since it just does a “loop” through the XML file, so I’m not sure how I would add a radio button, or a check box in each cell. * This isn’t as important for now, I’ll work on that after I’d rather have help with what I mentioned before, but this would be helpful too.

EDIT:

I have two problems.
I managed to add check boxes by doing something like this:

<td colspan="1"><input type="checkbox" name="Zone1" id="Zone1" /><xsl:value-of select="Zone[1]/Label"/></td>
<td colspan="1"><input type="checkbox" name="Zone2" id="Zone1" /><xsl:value-of select="Zone[2]/Label"/></td>
<td colspan="1"><input type="checkbox" name="Zone3" id="Zone1"/> <xsl:value-of select="Zone[3]/Label"/></td>
<td colspan="1"><input type="checkbox" name="Zone4" id="Zone1" /><xsl:value-of select="Zone[4]/Label"/></td>

The problem is, I think every elements in each column will have the same ID, am I right? How do I change it so they all have a different ID?

Also, it can’t be seen from the XML file in my question, but later on there would only be, for example, Milk4. meaning I would want the cells for Water4 and Juice4 to dissapear completely, but it’s still there, empty with a check box.

  • 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-06-16T03:25:17+00:00Added an answer on June 16, 2026 at 3:25 am

    For your second column, you are doing this

    <td>
       <xsl:attribute name="src">
       <xsl:value-of select="image/File"/>
       </xsl:attribute>
    </td>
    

    But this results in the following HTML

    <td src="milk.jpg" />
    

    However, you really need to use the img tag to display the image, so do this instead.

    <td>
       <img src="{image/File}" />
    </td>
    

    As for the third and fourth columns, you can add an xpath expression to specify the position.

    <xsl:value-of select="Zone[1]/Label"/>
    <xsl:value-of select="Zone[2]/Label"/>
    

    In fact, to avoid some code repetition, it might be better to use template matching here

     <xsl:apply-templates select="Zone[position() &lt; 3]" />
    
     <xsl:template match="Zone">
         <xsl:value-of select="Label"/>
     </xsl:template>
    

    And if you wanted to extend this to show your check boxes, you could do something like this

    <xsl:template match="Zone">
       <xsl:variable name="index">
          <xsl:number />
       </xsl:variable>
       <input type="checkbox" name="Zone{$index}" id="Zone{$index}" />
       <xsl:value-of select="Label"/>
    </xsl:template>
    

    Note how this makes use of “Attribute Value Templates” to output the id. The curly braces { } indicate it is an expression to be evaluated, rather than output literally.

    Here is the full XSLT

    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
       <xsl:output method="xml" indent="yes"/>
    
       <xsl:template match="/List">
          <table border="1">
             <tr>
                <th>Column 1</th>
                <th>Image</th>
                <th>Column 3</th>
             </tr>
             <xsl:for-each select="Classification/Class">
                <tr>
                   <td>
                      <em>
                         <xsl:value-of select="Label"/>
                      </em>
                   </td>
                   <td>
                      <img src="{image/File}"/>
                   </td>
                   <td colspan="1"><xsl:apply-templates select="Zone[1]" /></td>
                   <td colspan="1"><xsl:apply-templates select="Zone[2]" /></td>
                   <td colspan="1"><xsl:apply-templates select="Zone[3]" /></td>
                   <td colspan="1"><xsl:apply-templates select="Zone[4]" /></td>
                </tr>
             </xsl:for-each>
          </table>
       </xsl:template>
    
       <xsl:template match="Zone">
          <xsl:variable name="index">
             <xsl:number />
          </xsl:variable>
          <input type="checkbox" name="Zone{$index}" id="Zone{$index}" />
          <xsl:value-of select="Label"/>
       </xsl:template>
    </xsl:stylesheet>
    

    When applied to your XML, the following is output

    <table border="1">
       <tr>
          <th>Column 1</th>
          <th>Image</th>
          <th>Column 3</th>
       </tr>
       <tr>
          <td>
             <em>Milk</em>
          </td>
          <td>
             <img src="milk.jpg"/>
          </td>
          <td colspan="1">
             <input type="checkbox" name="Zone1" id="Zone1"/>Milk1</td>
          <td colspan="1">
             <input type="checkbox" name="Zone2" id="Zone2"/>Milk2</td>
          <td colspan="1">
             <input type="checkbox" name="Zone3" id="Zone3"/>Milk3</td>
          <td colspan="1">
             <input type="checkbox" name="Zone4" id="Zone4"/>Milk4</td>
       </tr>
       <tr>
          <td>
             <em>Water</em>
          </td>
          <td>
             <img src="water.jpg"/>
          </td>
          <td colspan="1">
             <input type="checkbox" name="Zone1" id="Zone1"/>Water1</td>
          <td colspan="1">
             <input type="checkbox" name="Zone2" id="Zone2"/>Water2</td>
          <td colspan="1"/>
          <td colspan="1"/>
       </tr>
       <tr>
          <td>
             <em>Juice</em>
          </td>
          <td>
             <img src="juice.jpg"/>
          </td>
          <td colspan="1">
             <input type="checkbox" name="Zone1" id="Zone1"/>Juice1</td>
          <td colspan="1">
             <input type="checkbox" name="Zone2" id="Zone2"/>Juice2</td>
          <td colspan="1"/>
          <td colspan="1"/>
       </tr>
    </table>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to create an XML sitemap using CakePHP, from a table which has
Pretty new to sqlite (and sql). Trying to modify one table using another. create
I am trying to create a new XML file from an exisiting one using
I am trying to create a table using Xml/Xslt, where some of the cells
I am trying to create a table in MySql using php. My code looks
I am trying to create a table with a single column using the following
I'm trying to duplicate a table using phpmyadmin. It generates the following query: CREATE
I'm trying to create an sql table called 'cartable'. I'm currently using phpmyadmin via
I am trying to create a @OneToMany relationship in JPA using the following table
I'm trying to query an xml file using the following xslt: <xsl:stylesheet version=1.0 xmlns:xsl=http://www.w3.org/1999/XSL/Transform

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.