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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T17:09:14+00:00 2026-05-28T17:09:14+00:00

My source XML provides data column-by-column; the cells have varying heights. Using XSLT 1.0,

  • 0

My source XML provides data column-by-column; the cells have varying heights. Using XSLT 1.0, I need to pivot this around to match HTML’s row-by-row table format.

Example: I need to convert input data like this

<source>
    <column>
        <cell height="1">col A row  1</cell>
        <cell height="2">col A rows 2-3</cell>
    </column>
    <column>
        <cell height="1">col B row  1</cell>
        <cell height="1">col B row  2</cell>
        <cell height="1">col B row  3</cell>
    </column>
    <column>
        <cell height="3">col C rows 1-3</cell>
    </column>
</source>

into an HTML table like this

<table>
    <tr>
        <td rowspan="1">col A row  1</td>
        <td rowspan="1">col B row  1</td>
        <td rowspan="3">col C rows 1-3</td>
    </tr>
    <tr>
        <td rowspan="2">col A rows 2-3</td>
        <td rowspan="1">col B row  2</td>
    </tr>
    <tr>
        <td rowspan="1">col B row  3</td>
    </tr>
</table>

How?

Edit: Here is another example, one where no single column has as many cells as there are table rows.

<source>
    <column id="A">
        <cell height="1">col A row  1</cell>
        <cell height="2">col A rows 2-3</cell>
    </column>
    <column id="B">
        <cell height="2">col B row  1-2</cell>
        <cell height="1">col B row  3</cell>
    </column>
    <column id="C">
        <cell height="3">col C rows 1-3</cell>
    </column>
</source>

into an HTML table like this

<table>
    <tr>
        <td rowspan="1">col A row  1</td>
        <td rowspan="2">col B row  1-2</td>
        <td rowspan="3">col C rows 1-3</td>
    </tr>
    <tr>
        <td rowspan="2">col A rows 2-3</td>
    </tr>
    <tr>
        <td rowspan="1">col B row  3</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-05-28T17:09:15+00:00Added an answer on May 28, 2026 at 5:09 pm

    I. XSLT 1.0 solution

    This transformation:

    <xsl:stylesheet version="1.0"
     xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
     xmlns:ext="http://exslt.org/common" exclude-result-prefixes="ext">
     <xsl:output omit-xml-declaration="yes" indent="yes"/>
     <xsl:strip-space elements="*"/>
    
     <xsl:variable name="vrtfPass1">
      <xsl:apply-templates mode="pass1"/>
     </xsl:variable>
    
     <xsl:variable name="vPass1"
       select="ext:node-set($vrtfPass1)"/>
    
     <xsl:variable name="vMaxRow">
      <xsl:for-each select=
        "$vPass1/*/*/cell/@startRow">
        <xsl:sort select="." data-type="number" order="descending"/>
    
        <xsl:if test="position() = 1">
         <xsl:value-of select="."/>
        </xsl:if>
      </xsl:for-each>
     </xsl:variable>
    
     <xsl:template match="node()|@*" mode="pass1">
      <xsl:copy>
       <xsl:apply-templates select="node()|@*" mode="pass1"/>
      </xsl:copy>
     </xsl:template>
    
     <xsl:template match="cell" mode="pass1">
      <cell height="{@height}"
       startRow="{sum(preceding-sibling::*/@height) +1}">
       <xsl:copy-of select="text()"/>
      </cell>
     </xsl:template>
    
     <xsl:template match="/">
      <table>
        <xsl:call-template name="makeRows">
         <xsl:with-param name="pmaxRow" select="$vMaxRow"/>
        </xsl:call-template>
      </table>
     </xsl:template>
    
     <xsl:template name="makeRows">
      <xsl:param name="prowNum" select="1"/>
      <xsl:param name="pmaxRow" select="1"/>
    
      <xsl:if test="not($prowNum > $pmaxRow)">
        <tr>
          <xsl:apply-templates select=
          "$vPass1/*/*/cell[@startRow = $prowNum]"/>
        </tr>
    
        <xsl:call-template name="makeRows">
         <xsl:with-param name="prowNum" select="$prowNum+1"/>
         <xsl:with-param name="pmaxRow" select="$pmaxRow"/>
        </xsl:call-template>
      </xsl:if>
     </xsl:template>
    
     <xsl:template match="cell">
      <td rowspan="{@height}"><xsl:value-of select="."/></td>
     </xsl:template>
    </xsl:stylesheet>
    

    when applied on the provided XML document:

    <source>
        <column>
            <cell height="1">col A row  1</cell>
            <cell height="2">col A rows 2-3</cell>
        </column>
        <column>
            <cell height="2">col B row  1-2</cell>
            <cell height="1">col B row  3</cell>
        </column>
        <column>
            <cell height="3">col C rows 1-3</cell>
        </column>
    </source>
    

    produces the wanted, correct result:

    <table>
       <tr>
          <td rowspan="1">col A row  1</td>
          <td rowspan="2">col B row  1-2</td>
          <td rowspan="3">col C rows 1-3</td>
       </tr>
       <tr>
          <td rowspan="2">col A rows 2-3</td>
       </tr>
       <tr>
          <td rowspan="1">col B row  3</td>
       </tr>
    </table>
    

    II. XSLT 2.0 solution:

    This is similar to the XSLT 1.0 solution, but we use the max() function and also avoid the recursion by usig the to operator.

    <xsl:stylesheet version="2.0"
     xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
     xmlns:xs="http://www.w3.org/2001/XMLSchema"
     exclude-result-prefixes="xs">
     <xsl:output omit-xml-declaration="yes" indent="yes"/>
     <xsl:strip-space elements="*"/>
    
     <xsl:variable name="vPass1">
      <xsl:apply-templates mode="pass1"/>
     </xsl:variable>
    
     <xsl:variable name="vMaxRow" as="xs:integer"
      select="max($vPass1/*/*/cell/@startRow/xs:integer(.))"/>
    
     <xsl:template match="node()|@*" mode="pass1">
      <xsl:copy>
       <xsl:apply-templates select="node()|@*" mode="pass1"/>
      </xsl:copy>
     </xsl:template>
    
     <xsl:template match="cell" mode="pass1">
      <cell height="{@height}"
       startRow="{sum(preceding-sibling::*/@height) +1}">
       <xsl:copy-of select="text()"/>
      </cell>
     </xsl:template>
    
     <xsl:template match="/">
      <table>
        <xsl:for-each select="1 to $vMaxRow">
          <tr>
            <xsl:apply-templates select=
              "$vPass1/*/*/cell[@startRow = current()]"/>
          </tr>
        </xsl:for-each>
      </table>
     </xsl:template>
    
     <xsl:template match="cell">
      <td rowspan="{@height}"><xsl:value-of select="."/></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 need to load an XML source using Simple XML, duplicate an existing node
I'm using the XML data source feature in Reporting Services 2005 but having some
This is my persistence.xml : <persistence> <persistence-unit name=MyUnit> <provider>org.hibernate.ejb.HibernatePersistence</provider> <jta-data-source>jdbc/abcDS</jta-data-source> </persistence-unit> </persistence> This is
I have a source XML file that is used to create C# files that
Have a source xml document that uses namespace containing prefixes and a default namespace.
I want to transform an XML document. The source XML looks like this: <svc:ElementList>
I would like to process a frame element in my source xml file using
I have an XML source in a Microsoft SSIS 2005 package and when I
I have the following XML source structure: <turnovers> <turnover repid=1 amount=500 rate=0.1/> <turnover repid=5
I have been tasked with finding an open source DOM XML parser. The parser

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.