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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T04:45:52+00:00 2026-06-14T04:45:52+00:00

I have another XSLT question which follows on from the question I asked last

  • 0

I have another XSLT question which follows on from the question I asked last week.
XSL for Xml to table transformation for two rows and many columns.

The challenges is to insert different classes for each according to the section attribute. And I need two different outputs as hown in the output below. I have an example XSLT from my previous question, which I want to edited accordingly.

Please note I’m working with XSLT 1.0. Any advice or guidance will be much appreciate.

Input:

<root>
  <page number="1" section="Arsenal">Arsenal</page> 
  <page number="2" section="Arsenal">Arsenal</page> 
  <page number="3" section="Arsenal">Arsenal</page> 
  <page number="4" section="Arsenal">Arsenal</page> 
  <page number="5" section="Arsenal">Arsenal</page> 
  <page number="6" section="Arsenal">Arsenal</page> 
  <page number="7" section="Chelsea">Chelsea</page> 
  <page number="8" section="Chelsea">Chelsea</page> 
  <page number="9" section="Chelsea">Chelsea</page> 
  <page number="10" section="Chelsea">Chelsea</page> 
  <page number="11" section="Chelsea">Chelsea</page> 
  <page number="12" section="Chelsea">Chelsea</page> 
  <page number="13" section="ManUnited">ManUnited</page> 
  <page number="14" section="ManUnited">ManUnited</page> 
  <page number="15" section="ManUnited">ManUnited</page> 
  <page number="16" section="ManUnited">ManUnited</page> 
  <page number="17" section="ManUnited">ManUnited</page> 
  <page number="18" section="ManUnited">ManUnited</page> 
  <page number="19" section="ManCity">ManCity</page> 
  <page number="20" section="ManCity">ManCity</page> 
  <page number="21" section="ManCity">ManCity</page> 
  <page number="22" section="ManCity">ManCity</page> 
  <page number="23" section="ManCity">ManCity</page> 
  <page number="24" section="ManCity">ManCity</page> 
 </root>

Output 1:

<table>
<tr>
<td class="AFC">Arsenal</td>
<td></td>
<td class="CFC">Chelsea</td>
<td></td>
<td class="MUFC">ManUnited</td>
<td></td>
<td class="MCFC">ManCity</td>
<td></td>
</tr>
<tr>
<td>1</td>
<td>6</td>
<td>7</td>
<td>12</td>
<td>13</td>
<td>18</td>
<td>19</td>
<td>24</td>
</tr>
</table>

Output 2:

<table>
<tr>
<td class="Arsenal">Arsenal</td>
<td></td>
<td class="Chelsea">Chelsea</td>
<td></td>
<td class="ManUnited">ManUnited</td>
<td></td>
<td class="ManCity">ManCity</td>
<td></td>
</tr>
<tr>
<td>1</td>
<td>6</td>
<td>7</td>
<td>12</td>
<td>13</td>
<td>18</td>
<td>19</td>
<td>24</td>
</tr>
</table>

Current XSLT provide by @Kirill Polishchuk

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" omit-xml-declaration="yes" indent="yes"/>
<xsl:key name="k" match="page" use="@section"/>

<xsl:template match="/root">
<table>
<tr>
<xsl:apply-templates select="page[generate-id() = generate-id(key('k', @section))]"/>
</tr>
<tr>
<xsl:apply-templates select="page[generate-id() = generate-id(key('k', @section))]" mode="page"/>
</tr>
</table>
</xsl:template>

<xsl:template match="page">
<td>
<xsl:value-of select="."/>
</td>
<td></td>
</xsl:template>

<xsl:template match="page" mode="page">
<td>
<xsl:value-of select="@number"/>
</td>
<td>
<xsl:value-of select="key('k', @section)[last()]/@number"/>
</td>
</xsl:template>

</xsl:stylesheet>
  • 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-14T04:45:53+00:00Added an answer on June 14, 2026 at 4:45 am

    Use this XSLT:

    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:my="my">
      <xsl:output method="xml" omit-xml-declaration="yes" indent="yes"/>
    
      <xsl:key name="k" match="page" use="@section"/>
    
      <xsl:param name="short-name" select="true()"/>
      <!-- Change param to false()-->
    
      <my:data>
        <club name="Arsenal">AFC</club>
        <club name="Chelsea">CFC</club>
        <club name="ManUnited">MUFC</club>
        <club name="ManCity">MCFC</club>
      </my:data>
    
      <xsl:template match="/root">
        <table>
          <tr>
            <xsl:apply-templates select="page[generate-id() = generate-id(key('k', @section))]"/>
          </tr>
          <tr>
            <xsl:apply-templates select="page[generate-id() = generate-id(key('k', @section))]" mode="page"/>
          </tr>
        </table>
      </xsl:template>
    
      <xsl:template match="page">
        <xsl:variable name="class">
          <xsl:choose>
            <xsl:when test="$short-name">
              <xsl:value-of select="document('')/*/*/club[@name = current()/@section]"/>
            </xsl:when>
            <xsl:otherwise>
              <xsl:value-of select="@section"/>
            </xsl:otherwise>
          </xsl:choose>
    
        </xsl:variable>
    
        <td class="{$class}">
          <xsl:value-of select="."/>
        </td>
        <td></td>
      </xsl:template>
    
      <xsl:template match="page" mode="page">
        <td>
          <xsl:value-of select="@number"/>
        </td>
        <td>
          <xsl:value-of select="key('k', @section)[last()]/@number"/>
        </td>
      </xsl:template>
    
    </xsl:stylesheet>
    

    Depending on parameter $short-name it renders your 1st desired XML or 2nd.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Another Newbie question in XSLT transformation. (I have asked similar question before, but in
I have a .xslt that translates xml from one form to another (I'm not
i have another question on getting my XML serialization neat, which i can't seem
XSLT XML Question. I have another variation of my previous question. I have to
I have to convert from one XML (XHTML) file to another using XSLT. The
I have to convert from one XML (XHTML) file to another using XSLT. The
I have to transfrom from one XML to another by using XSLT. I have
I have an xslt script that transforms an xml file to another xml file.
I have the following node I need to parse using XSLT 1.0 from xml
I have an XML to which i need to apply a XSL to 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.