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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T02:40:09+00:00 2026-05-27T02:40:09+00:00

My question is a bit similar to XML to HTML table with XSLT .

  • 0

My question is a bit similar to XML to HTML table with XSLT .

I have a dictionary defined as follows in XML:

<dictionary>
    <languages>
        <language>en</language>
        <language>ja</language>
    </languages>
    <entries>
        <entry id="1">
            <en>Test</en>
            <ja>テスト</ja>
        </entry>
        <entry id="2">
            <en>Test2</en>
            <ja>テスト2</en>
        </entry>
    </entries>
</dictionary>

And I would like the following output in XHTML:

<table>
    <thead>
        <tr>
            <th>en</th>
            <th>ja</th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td>Test</td>
            <td>テスト</td>
        </tr>
        <tr>
            <td>Test2</td>
            <td>テスト2</td>
        </tr>
    </tbody>
</table>

I adapted the answer from XML to HTML table with XSLT as follows:

<xsl:stylesheet version="1.0"
 xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
 <xsl:output omit-xml-declaration="yes" indent="yes"/>

 <xsl:template match="//dictionary/entries">
     <table><xsl:apply-templates select="entry"/></table>
 </xsl:template>

 <xsl:template match="entry[1]">
  <thead><tr><xsl:apply-templates select="*" mode="header"/></tr></thead>
  <xsl:call-template name="standardRow"/>
 </xsl:template>

 <xsl:template match="entry" name="standardRow">
  <tbody><tr><xsl:apply-templates select="*"/></tr></tbody>
 </xsl:template>

 <xsl:template match="entry/*">
  <td><xsl:apply-templates select="node()"/></td>
 </xsl:template>

 <xsl:template match="entry/*" mode="header">
  <th><xsl:value-of select="name()"/></th>
 </xsl:template>
</xsl:stylesheet>

The thing is that I might have inputs as follows:

<dictionary>
    <languages>
        <language>en</language>
        <language>ja</language>
            <language>id</language>
    </languages>
    <entries>
        <entry id="1">
            <en>Test</en>
            <ja>テスト</ja>
        </entry>
        <entry id="2">
            <ja>テスト2</ja>
            <en>Test2</en>
            <id>uji2</id>
        </entry>
    </entries>
</dictionary>

As you might have understood, XSLT takes the first entry node to define the column names and the column id is not generated. Moreover, if the language order is changed in entry the <td> do not appear in order.

With the input above, I would like the following output:

<table>
    <thead>
        <tr>
            <th>en</th>
            <th>ja</th>
            <th>id</th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td>Test</td>
            <td>テスト</td>
            <td></td>
        </tr>
        <tr>
            <td>Test2</td>
            <td>テスト2</td>
            <td>Uji2</td>
        </tr>
    </tbody>
</table>

This is my first time using XSLT and I do not really know how I could do this. I guess I could use the languages node. Please note that the XML input format is flexible and I would welcome any suggestions even if I need to change the format.

  • 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-27T02:40:10+00:00Added an answer on May 27, 2026 at 2:40 am

    Here is a sample stylesheet:

    <xsl:stylesheet
      xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
      version="1.0">
    
      <xsl:output method="html" indent="yes"/>
    
      <xsl:key name="k1" match="entry/*" use="concat(generate-id(..), '|', local-name())"/>
    
      <xsl:variable name="languages" select="/dictionary/languages/language"/>
    
      <xsl:template match="dictionary">
        <xsl:apply-templates select="entries"/>
      </xsl:template>
    
      <xsl:template match="entries">
        <table>
          <thead>
            <tr>
              <xsl:apply-templates select="$languages" mode="header"/>
            </tr>
          </thead>
          <tbody>
            <xsl:apply-templates/>
          </tbody>
        </table>
      </xsl:template>
    
      <xsl:template match="language" mode="header">
        <th>
          <xsl:value-of select="."/>
        </th>
      </xsl:template>
    
      <xsl:template match="entry">
        <tr>
          <xsl:apply-templates select="$languages">
            <xsl:with-param name="entry" select="current()"/>
          </xsl:apply-templates>
        </tr>
      </xsl:template>
    
      <xsl:template match="language">
        <xsl:param name="entry"/>
        <td>
          <xsl:value-of select="key('k1', concat(generate-id($entry), '|', .))"/>      
        </td>
      </xsl:template>
    </xsl:stylesheet>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have made a question which is a bit similar to this, though the
I have a need that is a bit similar to this question , except
My question is similar to Engram's here , but my question goes a bit
I've searched a bit and didn't see any similar question, so here goes. How
Bit support question. Apologies for that. I have an application linked with GNU readline.
I have little bit longer question for you - but hope answer will be
Sorry if the question is bit confusing. This is similar to this question I
My question is very similar to this question but a bit more specific. My
I've kind of asked this question earlier so sorry for asking a bit similar
This is similar to this question , although a bit broader. I'm just opening

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.