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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T04:00:12+00:00 2026-06-18T04:00:12+00:00

I have another question regarding XSLT transformation for tables with fixed structure and variable

  • 0

I have another question regarding XSLT transformation for tables with fixed structure and variable input content.

I have outlined 2 different examples.

But the desired table class is dependent on the number of sections in input XML.

I have a previous example to start from provided by @Kirill Polishchuk and @JLRishe

Extracting a class from the section attribute using xsl

XSLT transformation into fixed table structure

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

Example 1

Input XML with 6 sections

<root>
  <page number="1" section="Arsenal_Stadium">Arsenal_Stadium</page> 
  <page number="2" section="Arsenal_Stadium">Arsenal_Stadium</page> 
  <page number="3" section="Arsenal_Stadium">Arsenal_Stadium</page> 
  <page number="4" section="Arsenal_Stadium">Arsenal_Stadium</page> 
  <page number="5" section="Arsenal_Crowds">Arsenal_Crowds</page> 
  <page number="6" section="Arsenal_Crowds">Arsenal_Crowds</page> 
  <page number="7" section="Arsenal_Crowds">Arsenal_Crowds</page> 
  <page number="8" section="Arsenal_Crowds">Arsenal_Crowds</page> 
  <page number="9" section="Arsenal_Support">Arsenal_Support</page> 
  <page number="10" section="Arsenal_Support">Arsenal_Support</page> 
  <page number="11" section="Arsenal_Support">Arsenal_Support</page> 
  <page number="12" section="Arsenal_Support">Arsenal_Support</page> 
  <page number="13" section="Arsenal_Revenue">Arsenal_Revenue</page> 
  <page number="14" section="Arsenal_Revenue">Arsenal_Revenue</page> 
  <page number="15" section="Arsenal_Revenue">Arsenal_Revenue</page> 
  <page number="16" section="Arsenal_Revenue">Arsenal_Revenue</page> 
  <page number="17" section="Arsenal_Cost">Arsenal_Cost</page> 
  <page number="18" section="Arsenal_Cost">Arsenal_Cost</page> 
  <page number="19" section="Arsenal_Cost">Arsenal_Cost</page> 
  <page number="20" section="Arsenal_Cost">Arsenal_Cost</page> 
  <page number="21" section="Arsenal_Outlook">Arsenal_Outlook</page> 
  <page number="22" section="Arsenal_Outlook">Arsenal_Outlook</page> 
  <page number="23" section="Arsenal_Outlook">Arsenal_Outlook</page> 
  <page number="24" section="Arsenal_Outlook">Arsenal_Outlook</page> 
 </root>

Desired Output

<table class="col_6">
<tr>
<td class="Stadium">Stadium</td>
<td class="Crowds">Crowds</td>
<td class="Support">Support</td>
<td class="Revenue">Revenue</td>
<td class="Cost">Cost</td>
<td class="Outlook">Outlook</td>
</tr>
<tr>
<td class="Stadium_R2">1-4</td>
<td class="Crowds_R2">5-6</td>
<td class="Support_R2">7-10</td>
<td class="Revenue_R2">11-14</td>
<td class="Cost_R2">15-18</td>
<td class="Outlook_R2">19-22</td>
</tr>
</table>

Example 2

Input XML 4 sections

<root>
  <page number="1" section="Arsenal_Stadium">Arsenal_Stadium</page> 
  <page number="2" section="Arsenal_Stadium">Arsenal_Stadium</page> 
  <page number="3" section="Arsenal_Stadium">Arsenal_Stadium</page> 
  <page number="4" section="Arsenal_Stadium">Arsenal_Stadium</page> 
  <page number="5" section="Arsenal_Support">Arsenal_Support</page> 
  <page number="6" section="Arsenal_Support">Arsenal_Support</page> 
  <page number="7" section="Arsenal_Support">Arsenal_Support</page> 
  <page number="8" section="Arsenal_Support">Arsenal_Support</page> 
  <page number="9" section="Arsenal_Cost">Arsenal_Cost</page> 
  <page number="10" section="Arsenal_Cost">Arsenal_Cost</page> 
  <page number="11" section="Arsenal_Cost">Arsenal_Cost</page> 
  <page number="12" section="Arsenal_Cost">Arsenal_Cost</page> 
  <page number="13" section="Arsenal_Outlook">Arsenal_Outlook</page> 
  <page number="14" section="Arsenal_Outlook">Arsenal_Outlook</page> 
  <page number="15" section="Arsenal_Outlook">Arsenal_Outlook</page> 
  <page number="16" section="Arsenal_Outlook">Arsenal_Outlook</page> 
 </root>

Desired Output

<table class="col_4">
<tr>
<td class="Stadium">Stadium</td>
<td class="Support">Support</td>
<td class="Cost">Cost</td>
<td class="Outlook">Outlook</td>
</tr>
<tr>
<td class="Stadium_R2">1-4</td>
<td class="Support_R2">5-8</td>
<td class="Cost_R2">9-12</td>
<td class="Outlook_R2">13-16</td>
</tr>
</table>
  • 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-18T04:00:14+00:00Added an answer on June 18, 2026 at 4:00 am

    This should do it:

    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
      <xsl:output method="xml" indent="yes" omit-xml-declaration="yes"/>
      <xsl:key name="kGroup" match="page" use="@section"/>
    
      <xsl:template match="/*">
        <xsl:variable name="groups"
           select="*[generate-id() = generate-id(key('kGroup', @section)[1])]" />
    
        <table class="col_{count($groups)}">
          <tr>
            <xsl:apply-templates select="$groups" mode="top" />
          </tr>
          <tr>
            <xsl:apply-templates select="$groups" mode="pageNums" />
          </tr>
        </table>
      </xsl:template>
    
      <xsl:template match="page" mode="top">
        <xsl:variable name="sectName" select="substring-after(@section, 'Arsenal_')" />
        <td class="{$sectName}">
          <xsl:value-of select="$sectName" />
        </td>
      </xsl:template>
    
      <xsl:template match="page" mode="pageNums">
        <xsl:variable name="groupMembers" select="key('kGroup', @section)" />
        <td class="{substring-after(@section, 'Arsenal_')}_R2">
          <xsl:value-of select="concat($groupMembers[1]/@number, '-', 
                                       $groupMembers[last()]/@number)"/>
        </td>
      </xsl:template>
    </xsl:stylesheet>
    

    When run on your first input:

    <table class="col_6">
      <tr>
        <td class="Stadium">Stadium</td>
        <td class="Crowds">Crowds</td>
        <td class="Support">Support</td>
        <td class="Revenue">Revenue</td>
        <td class="Cost">Cost</td>
        <td class="Outlook">Outlook</td>
      </tr>
      <tr>
        <td class="Stadium_R2">1-4</td>
        <td class="Crowds_R2">5-8</td>
        <td class="Support_R2">9-12</td>
        <td class="Revenue_R2">13-16</td>
        <td class="Cost_R2">17-20</td>
        <td class="Outlook_R2">21-24</td>
      </tr>
    </table>
    

    When run on your second input:

    <table class="col_4">
      <tr>
        <td class="Stadium">Stadium</td>
        <td class="Support">Support</td>
        <td class="Cost">Cost</td>
        <td class="Outlook">Outlook</td>
      </tr>
      <tr>
        <td class="Stadium_R2">1-4</td>
        <td class="Support_R2">5-8</td>
        <td class="Cost_R2">9-12</td>
        <td class="Outlook_R2">13-16</td>
      </tr>
    </table>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have another question for the masses out there regarding trying to input values
I have a question regarding the creation of a utility that executes another command.
another noob question regarding F#. If I have the following code... let ExeC =
I have a question regarding copying cells from one sheet to another using VBA.
I have yet another question regarding the randomization of data! $gender=''; if(isset($_GET['gender'])) { $gender=$_GET['gender'];
I have a rather strange question regarding urls which point to another url. So,
After trying this solution and getting one step further i have another question regarding
A simple question regarding multhreading programming: I have an NSMutableArray instance variable that is
I have question regarding Java Comparator. Or maybe you all have another Idea to
I have a question regarding a database query on unrelated tables. It is required

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.