HTML to CSV using xslt

Hi all,

I need an xslt to convert HTML to CSV. I know there are other ways to convert but I have a process which only accept xslt to convert HTML to CSV.
I am attaching source HTML file and csv file i want, can some one please create xslt for me. Appreciate any help on this since this is an urgent requirement and i am new to xslt.

Essentially below file lines of the csv files are 1 on 1. and you can get them in the body part pasted below.

Total Transactions:,245
Successful Transactions:,243
Failed Transactions:,2
Duplicate Transactions:,0
Unprocessed Transactions:,0
Transaction,Error Message,Details

 <body>
        <div class="container-fluid">
          <h4>Upload Summary</h4>
          <div class="row">
            <div class="col-md-4">
              <table class="table table-bordered table-striped table-condensed">
                <tr>
                  <td>
                    <b>Total Transactions:</b>
                  </td>
                  <td align="right">245</td>
                </tr>
                <tr>
                  <td colspan="2">
                    <hr/>
                  </td>
                </tr>
                <tr>
                  <td align="right">
                    <b>Successful Transactions:</b>
                  </td>
                  <td align="right">243</td>
                </tr>
                <tr>
                  <td align="right">
                    <b>Failed Transactions:</b>
                  </td>
                  <td align="right">2</td>
                </tr>
                <tr>
                  <td align="right">
                    <b>Duplicate Transactions:</b>
                  </td>
                  <td align="right">0</td>
                </tr>
                <tr>
                  <td align="right">
                    <b>Unprocessed Transactions:</b>
                  </td>
                  <td align="right">0</td>
                </tr>
              </table>
            </div>
          </div>
          <hr/>
          <h5>Error Summary</h5>
          <div class="row">
            <div class="col-md-12">
              <table class="table table-bordered table-striped table-condensed tablesorter">
                    <thead>
                     <tr>
                       <th class="col-md-1" align="center">Transaction</th>
                       <th class="col-md-10">Error Message</th>
                       <th class="col-md-1" align="center">Details</th>
                     </tr>
                  </thead>
                  <tbody>
FailureReport--19-.html
convertcsv.csv
Sridhar LenkalaAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Geert BormansInformation ArchitectCommented:
Well, if you urgently need someone to develop your XSLT you basically have two options
- write decent specs and hire a freelancer
- learn XSLT as fast as you can and come back here with questions

You did not give us any background here, you just dumped input and output (and the output isn't even valid CSV)
It is very tempting to just tell you to find a different solution, this is not what Experts Exchange is for

I did some first attempt so you have something to start learning

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:html="http://www.w3.org/1999/xhtml"
    version="2.0">
    
    <xsl:strip-space elements="*"/>
    <xsl:output method="text"></xsl:output>
    
    <xsl:template match="/">
        <xsl:apply-templates select="//html:div[@class = 'col-md-4']/html:table"/>
    </xsl:template>
    
    <xsl:template match="html:table">
        <xsl:apply-templates select="html:tr[not(html:td/html:hr)]"/>
    </xsl:template>
    
    <xsl:template match="html:tr">
        <xsl:value-of select="html:td[1]"/>
        <xsl:text>,</xsl:text>
        <xsl:value-of select="html:td[2]"/>
        <xsl:text>&#10;</xsl:text>
    </xsl:template>
    
</xsl:stylesheet>

Open in new window


If you need more, you need to give more
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
David FavorLinux/LXD/WordPress/Hosting SavantCommented:
Keep in mind, your HTML will likely have to be well formed to use XSLT.

If your HTML is poorly formed (HTML syntax errors), use one of the many html2csv convertors available.
0
Geert BormansInformation ArchitectCommented:
@david
good point
note however that the poster of this question is using a tool that offers XSLT as its only means for processing the html
a process which only accept xslt to convert HTML to CSV
I have tested the XSLT I posted on the source HTML sent, and it is wellformed
(it is referencing the XHTML DTD and it is in the XHTML namespace by the way)
0
Geert BormansInformation ArchitectCommented:
It just answers the question in full.
Precise, to the point and relevant for future reference
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
HTML

From novice to tech pro — start learning today.