I got stuck with making the two options in converting html table into 2 types of xml. I needed to make a xslt to convert Html table like this
<categories>1 row</categories>
<dataset>1 column</dataset>
<table caption="City statistics">
<thead>
<tr>
<th id="1">Name</th> <th id="2">Population</th> <th id="3">Area</th><th id="4">Elevation</th>
</tr>
</thead>
<tbody>
<tr>
<td id="1">Moscow</td> <td id="2">4.7</td> <td id="3">11.54</td> <td id="4">13</td>
</tr>
<tr>
<td id="1">London</td> <td id="2">6</td> <td id="3">15.54</td> <td id="4">15</td>
</tr>
</tbody>
</table>
Into xml file like this if the had 1 row as a value(means taking categories out of header where id > 1).
<chart caption='City statistics' xAxisName='City name' yAxisName='Values'>
<categories>
<category label='Population' />
<category label='Area' />
<category label='Elevation' />
</categories>
<dataset seriesName='Moscow'>
<set value='4.7' />
<set value='11.54'/>
<set value='13' />
</dataset>
<dataset seriesName='London'>
<set value='6'/>
<set value='15.54'/>
<set value='15'/>
</dataset>
</chart>
And I got this xsl from Miam84 as a help here. And this is a solution for the first condition
And I needed to make a one xsl for two conditions. The otherwise condition is the xml where the had 1 column as a value( need to take categories from where id=1).
<chart caption='City statistics' xAxisName='Сharacteristics' yAxisName='Values'>
<categories>
<category label='Moscow' />
<category label='London' />
</categories>
<dataset seriesName='Population'>
<set value='4.7' />
<set value='6'/>
</dataset>
<dataset seriesName='Area'>
<set value='11.54'/>
<set value='15.54'/>
</dataset>
<dataset seriesName='Elevation'>
<set value='13' />
<set value='15'/>
</dataset>
</chart>
What I tried to do is:
<?xml version='1.0' encoding='utf-8' ?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="xml"/>
<!-- Default template -->
<xsl:template match="/">
<xsl:choose>
<xsl:when test="//categories[@place='head']" >
<chart caption="" xAxisName="" yAxisName="Values">
<xsl:attribute name="xAxisName">
<xsl:value-of select="html/categories"/>
</xsl:attribute>
<xsl:attribute name="caption">
<xsl:value-of select="html/table/@caption"/>
</xsl:attribute>
<xsl:apply-templates select="html/table/thead"/>
<xsl:apply-templates select="html/table/tbody/tr"/>
</chart>
</xsl:when>
<xsl:otherwise>
<chart caption="" xAxisName="" yAxisName="Values">
<xsl:attribute name="xAxisName">
<xsl:value-of select="html/dataset"/>
</xsl:attribute>
<xsl:attribute name="caption">
<xsl:value-of select="html/table/@caption"/>
</xsl:attribute>
<xsl:apply-templates select="html/table/thead"/>
<xsl:apply-templates select="html/table/tbody/tr"/>
</chart>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<!-- template for the thead = categories container -->
<xsl:template match="tbody">
<xsl:choose>
<xsl:when test="//categories[@place='head']" >
</xsl:when>
<xsl:otherwise>
<categories>
<xsl:apply-templates select="tr/td[@id=1]"/>
</categories>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template match="thead">
<xsl:choose>
<xsl:when test="//categories[@place='head']" >
<categories>
<xsl:apply-templates select="tr/th[@id > 1]"/>
</categories>
</xsl:when>
<xsl:otherwise>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<!-- template for the th = each category -->
<xsl:template match="th">
<xsl:choose>
<xsl:when test="//categories[@place='head']" >
<category>
<xsl:attribute name="label">
<xsl:value-of select="."/>
</xsl:attribute>
</category>
</xsl:when>
<xsl:otherwise>
<dataset seriesName="">
<xsl:attribute name="seriesName">
<xsl:value-of select="."/>
</xsl:attribute>
</dataset>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<!-- template for the tr = the dataset -->
<xsl:template match="tr">
<xsl:choose>
<xsl:when test="//categories[@place='head']" >
<dataset seriesName="">
<xsl:attribute name="seriesName">
<xsl:value-of select="td[@id=1]"/>
</xsl:attribute>
<xsl:apply-templates select="td[@id > 1]"/>
</dataset>
</xsl:when>
<xsl:otherwise>
<dataset seriesName="">
<xsl:attribute name="seriesName">
<xsl:value-of select="th[@id > 1]"/>
</xsl:attribute>
</dataset>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<!-- template for the td = the set tag -->
<xsl:template match="td">
<xsl:choose>
<xsl:when test="//categories[@place='head']" >
<set value="">
<xsl:attribute name="value">
<xsl:value-of select="."/>
</xsl:attribute>
</set>
</xsl:when>
<xsl:otherwise>
<category>
<xsl:attribute name="label">
<xsl:value-of select="."/>
</xsl:attribute>
</category>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template match="html">
</xsl:template>
</xsl:stylesheet>