Altova Mailing List Archives>Archive Index >microsoft.public.xsl Archive Home >Recent entries [Thread Prev] >Thread Next - Re: Converting html table to xml Converting html table to xmlTo: NULL Date: 5/2/2007 11:16:00 PM
If I have an html table such as:
<table>
<tr class="parent">
<td>pdata</td>
</tr>
<tr class="child">
<td>cdataa</td>
</tr>
<tr class="child">
<td>cdatab</td>
</tr>
<tr class="child">
<td>cdatac</td>
</tr>
<tr class="parent">
<td>pdatab</td>
</tr>
<tr class="child">
<td>cdatae</td>
</tr>
</table>
I'd like to get it to be
<root>
<parent>pdata
<child>cdataa</child>
<child>cdatab</child>
<child>cdatac</child>
</parent>
<parent>pdatab
<child>cdatae</child>
</parent>
</root>
I tried using this xslt stylesheet but of course it doesn't work since
I can't figure out how to get the "child" under the "parent". Any help
would be greatly appreciated. Thanks.
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/
Transform">
<xsl:output method="xml" omit-xml-declaration="yes"/>
<xsl:template match="/">
<root>
<xsl:apply-templates select="//table"/>
</root>
</xsl:template>
<xsl:template match="table">
<xsl:apply-templates select="tr[@class='parent']"/>
<xsl:apply-templates select="tr[@class='child']"/>
</xsl:template>
<xsl:template match="tr[@class='parent']">
<parent>
<xsl:value-of select="."/>
</parent>
</xsl:template>
<xsl:template match="tr[@class='child']">
<child>
<xsl:value-of select="."/>
</child>
</xsl:template>
</xsl:stylesheet>
| ||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
