Reputation: 834
i've the below XML document, where some cals table has to be created.
<table frame="none">
<tgroup cols="5" align="left" colsep="1" rowsep="1">
<colspec colwidth="20pt" colname="c1"/>
<colspec colwidth="70pt" colname="c2"/>
<colspec colwidth="10pt" colname="c3"/>
<colspec colwidth="20pt" colname="c4"/>
<colspec colwidth="75pt" colname="c5"/>
<thead>
<row>
<entry>
<para>Item</para>
</entry>
<entry align="center">
<para>Injury</para>
</entry>
<entry>
<para/>
</entry>
<entry>
<para>Percentage of loss of earning capacity</para>
</entry>
<entry>
<para/>
</entry>
</row>
</thead>
<tbody>
<row>
<entry>
<para>1.</para>
</entry>
<entry>
<para>Loss of 2 limbs ...................................................................</para>
</entry>
<entry morerows="7">
<para>}</para>
</entry>
<entry morerows="7">
<para>100</para>
</entry>
<entry morerows="7">
<para></para>
</entry>
</row>
<row>
<entry>
<para>2.</para>
</entry>
<entry>
<para>Loss of both hands or of all fingers and both thumbs ...</para>
</entry>
</row>
<row>
<entry>
<para>3.</para>
</entry>
<entry>
<para>Loss of both feet ................................................................</para>
</entry>
</row>
<row>
<entry>
<para>4.</para>
</entry>
<entry>
<para>Total loss of sight ...............................................................</para>
</entry>
</row>
<row>
<entry>
<para>5.</para>
</entry>
<entry>
<para>Total paralysis ....................................................................</para>
</entry>
</row>
<row>
<entry>
<para>6.</para>
</entry>
<entry>
<para>Injuries resulting in being permanently bedridden .......</para>
</entry>
</row>
<row>
<entry>
<para>7.</para>
</entry>
<entry>
<para>Paraplegia ..........................................................................</para>
</entry>
</row>
<row>
<entry>
<para>8.</para>
</entry>
<entry>
<para>Any other injury causing permanent total disablement ...</para>
</entry>
</row>
<row>
<entry>
<para>9.</para>
</entry>
<entry>
<para>Loss of arm at shoulder ....................................................</para>
</entry>
<entry>
<para/>
</entry>
<entry>
<para>75</para>
</entry>
<entry>
<para>80 (preferred hand)</para>
</entry>
</row>
<row>
<entry>
<para>10.</para>
</entry>
<entry>
<para>Ankylosis of shoulder joint—</para>
</entry>
<entry>
<para/>
</entry>
<entry>
<para/>
</entry>
<entry>
<para/>
</entry>
</row>
<row>
<entry>
<para/>
</entry>
<entry>
<para>in optimum position .....................................................</para>
</entry>
<entry>
<para/>
</entry>
<entry>
<para>35</para>
</entry>
<entry>
<para/>
</entry>
</row>
<row>
<entry>
<para/>
</entry>
<entry>
<para>in worst position ............................................................</para>
</entry>
<entry>
<para/>
</entry>
<entry>
<para>55</para>
</entry>
<entry>
<para/>
</entry>
</row>
<row>
<entry>
<para>11.</para>
</entry>
<entry>
<para>Loss of arm between elbow and shoulder .......................</para>
</entry>
<entry>
<para/>
</entry>
<entry>
<para>75</para>
</entry>
<entry>
<para>80 (preferred hand)</para>
</entry>
</row>
<row>
<entry>
<para>12.</para>
</entry>
<entry>
<para>Loss of arm at elbow ..........................................................</para>
</entry>
<entry>
<para/>
</entry>
<entry>
<para>75</para>
</entry>
<entry>
<para>80 (preferred hand)</para>
</entry>
</row>
<row>
<entry>
<para>13.</para>
</entry>
<entry>
<para>Ankylosis of the elbow joint—</para>
</entry>
<entry>
<para/>
</entry>
<entry>
<para/>
</entry>
<entry>
<para/>
</entry>
</row>
<row>
<entry>
<para/>
</entry>
<entry>
<para>in optimum position .....................................................</para>
</entry>
<entry>
<para/>
</entry>
<entry>
<para>30</para>
</entry>
<entry>
<para/>
</entry>
</row>
<row>
<entry>
<para/>
</entry>
<entry>
<para>in worst position ............................................................</para>
</entry>
<entry>
<para/>
</entry>
<entry>
<para>50</para>
</entry>
<entry>
<para/>
</entry>
</row>
<row>
<entry>
<para>14.</para>
</entry>
</row>
</tbody>
</tgroup>
</table>
here i've to create a table as shown in the below picture
i know its not a good idea to ask for code directly, i tried for normal tables(which were done), but i'm really unable to know how to do a cals table in xslt. please let me know how i can achieve doing these cals table.
Thanks
Upvotes: 0
Views: 509
Reputation: 122364
You say in a comment that you're looking for HTML output - well the input XML you're starting with has the right structure to convert directly into an HTML table with a 1-1 mapping of element names, you just need to turn the morerows="n"
of the source format into a rowspan="n+1"
in the HTML
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
<xsl:strip-space elements="*" />
<xsl:output method="html" indent="yes" />
<!-- these nodes have the same names in HTML -->
<xsl:template match="table | thead | tbody">
<xsl:copy><xsl:apply-templates /></xsl:copy>
</xsl:template>
<!-- row becomes tr -->
<xsl:template match="row">
<tr><xsl:apply-templates /></tr>
</xsl:template>
<!-- entry becomes td -->
<xsl:template match="entry">
<td><xsl:apply-templates select="@morerows|node()" /></td>
</xsl:template>
<xsl:template match="entry/@morerows">
<xsl:attribute name="rowspan" select="1 + ." />
</xsl:template>
</xsl:stylesheet>
We rely here on the default template rules for nodes that don't have an explicit template, which will process children recursively in the case of elements and output the text in the case of text nodes.
You've tagged the question XSLT 2.0 but for the record this is almost an XSLT 1.0 stylesheet, the only thing you'd have to change is that xsl:attribute
doesn't take a select
in 1.0, so instead of <xsl:attribute name="rowspan" select="..." />
you'd need <xsl:attribute name="rowspan"><xsl:value-of select="..." /></xsl:attribute>
.
Upvotes: 1