Hi,
I have an xml file which contain TABLES. As per the width of table I have to decide whether the table will transform to html or convert as an Image.
I'm going with logic where I'm taking the longest word of column as the length of that particular column. In the last I will add the length of all the columns (longest words). If it is more than 16 characters then the table will not transform.
And if it is less than 16 characters then it will transform.
I have write some code for the same but I'm stuck at XPath where I have to check the longest word in that column and then add all the columns to get the column width.
Below is XML file and XSLT code. Can you please look into this and do the needful. It is bit urgent.
Thanks,
Anil Yadav
XML File
Code:
<?xml version="1.0" encoding="UTF-8"?>
<body>
<TABLE border="0" width="100%" align="center" cellpadding="0" cellspacing="0" style="font-size: 10pt; font-family: 'Times New Roman', Times; color: #000000; background: #FFFFFF">
<TR>
<TD>Cell 1</TD>
<TD>Some text</TD>
<TD>Some text</TD>
<TD>Some text</TD>
</TR>
<TR>
<TD>Cell 2</TD>
<TD>Some text</TD>
<TD>Some more text</TD>
<TD></TD>
</TR>
<TR>
<TD>Cell 3</TD>
<TD>Less</TD>
<TD>Very very less</TD>
<TD>Sample</TD>
</TR>
</TABLE>
<TABLE>
<TR>
<TD>Cell 1</TD>
<TD>So</TD>
<TD>So</TD>
<TD>So</TD>
</TR>
<TR>
<TD>Cell 2</TD>
<TD>So</TD>
<TD>So</TD>
<TD></TD>
</TR>
<TR>
<TD>Cell 3</TD>
<TD></TD>
<TD>Very</TD>
<TD>Sam</TD>
</TR>
</TABLE>
</body>
XSLT CODE
Code:
<xsl:template match="TABLE">
<xsl:variable name="colCount" select="TR[1]//TD"/>
<xsl:for-each select="TR">
<xsl:for-each select="TD">
<xsl:for-each-group group-by="." select="for $x in tokenize(string(.), ' ') return string-length(($x))">
<!--xsl:if test="string-length(current-grouping-key())"-->
<word word="{current-grouping-key()}"/>
<!--/xsl:if-->
</xsl:for-each-group>
</xsl:for-each>
</xsl:for-each>
</xsl:template>