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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T01:51:44+00:00 2026-05-25T01:51:44+00:00

I’m checking to see if anyone has an XSLT laying around that transforms HTML

  • 0

I’m checking to see if anyone has an XSLT laying around that transforms HTML tables to CALS. I’ve found a lot of material on going the other way (CALS to HTML), but not from HTML. I thought somebody may have done this before so I don’t have to reinvent the wheel. I’m not looking for a complete solution. Just a starting point.

If I get far enough on my own, I’ll post it for future reference.

  • 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-25T01:51:45+00:00Added an answer on May 25, 2026 at 1:51 am

    I’ve come up with a much simpler solution than what @Flack linked to:

    <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
    <xsl:template match="tbody">
        <xsl:variable name="maxColumns">
            <xsl:for-each select="tr">
                <xsl:sort select="sum(td/@colspan) + count(td[not(@colspan)])" data-type="number"/>
                <xsl:if test="position() = last()">
                    <xsl:value-of select="sum(td/@colspan) + count(td[not(@colspan)])"/>
                </xsl:if>
            </xsl:for-each>
        </xsl:variable>
        <tgroup>
            <xsl:attribute name="cols">
                <xsl:value-of select="$maxColumns"/>
            </xsl:attribute>
            <xsl:apply-templates select="@*|node()"/>
        </tgroup>
    </xsl:template>
    
    <xsl:template match="td[@colspan > 1]">
        <entry>
            <xsl:attribute name="namest">
                <xsl:value-of select="sum(preceding-sibling::td/@colspan) + count(preceding-sibling::td[not(@colspan)]) + 1"/>
            </xsl:attribute>
            <xsl:attribute name="nameend">
                <xsl:value-of select="sum(preceding-sibling::td/@colspan) + count(preceding-sibling::td[not(@colspan)]) + @colspan"/>
            </xsl:attribute>
            <xsl:apply-templates select="@*[name() != 'colspan']|node()"/>
        </entry>
    </xsl:template>
    
    <xsl:template match="tr">
        <row>
            <xsl:apply-templates select="@*|node()"/>
        </row>
    </xsl:template>
    
    <xsl:template match="td">
        <entry>
            <xsl:apply-templates select="@*|node()"/>
        </entry>
    </xsl:template>
    
    <xsl:template match="td/@rowspan">
        <xsl:attribute name="morerows">
            <xsl:value-of select=". - 1"/>
        </xsl:attribute>
    </xsl:template>
    
    <!-- fallback rule -->
    <xsl:template match="@*|node()">
        <xsl:copy>
            <xsl:apply-templates select="@*|node()"/>
        </xsl:copy>
    </xsl:template>
    </xsl:stylesheet>
    

    There are two tricky points. First, a CALS table needs a tgroup/@cols attribute containing the number of columns. So we need to find the maximum number of cells in one row in the XHTML table – but we must heed colspan declarations so that a cell with colspan > 1 creates the right number of columns! The first template in my stylesheet does just that, based on @Tim C’s answer to the max cells per row problem.

    Another problem is that for multi-column cells XHTML says “this cell is 3 columns wide” (colspan=”3″) while CALS will say “this cell starts in column 2 and ends in column 4” (namest=”2″ nameend=”4″). That transformation is done in the second template in the stylesheet.

    The rest is indeed fairly straightforward. The stylesheet doesn’t deal with details like changing style=”width: 50%” into width=”50%” etc. but those are relatively common problems, I believe.

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

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I've got a string that has curly quotes in it. I'd like to replace
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
I want to count how many characters a certain string has in PHP, but
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have a French site that I want to parse, but am running into

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.