Trouble merging the Columns in XSLT <p>I have a XML and i am transforming it into HTML using XSLT. The current table structure is as below.</p> <pre><code> |-------------------------| |type |name |age | |data |john |28 | |comment |pass | | |-------------------------| </code></pre> <p>I am trying to merge the cell of row where col0='comment' in just two TD. First TD for 'comment' and second TD for 'pass'. I will add colspan =2 in second TD.</p> <p>I am trying to generate the following table structure from below Code. (The td with Pass will have colsapn=2)</p> <pre><code>|-------------------------| |type |name |age | |data |john |28 | |comment |pass | |-------------------------| </code></pre> <p>The XML sample data is as follows.</p> <pre><code>&lt;Form&gt; &lt;Log&gt; &lt;col0&gt;type&lt;/col0&gt; &lt;col1&gt;name&lt;/col1&gt; &lt;col2&gt;age&lt;/col2&gt; &lt;/Log&gt; &lt;Log&gt; &lt;col0&gt;data&lt;/col0&gt; &lt;col1&gt;john&lt;/col1&gt; &lt;col2&gt;28&lt;/col2&gt; &lt;/Log&gt; &lt;Log&gt; &lt;col0&gt;comment&lt;/col0&gt; &lt;col1&gt;passed&lt;/col1&gt; &lt;col2&gt;&lt;/col2&gt; &lt;/Log&gt; &lt;/Form&gt; </code></pre> <p>I am using the below XSLT code to do the transformation. But its not generating the expected result. This part of the bigger XML so i am putting the required code only.</p> <p>The code is as follows. I have removed the other part of the code which is of no use related to the issue.</p> <pre><code>&lt;xsl:for-each select="Form"&gt; -- Another code for Log position 1 &lt;xsl:apply-templates select="Log[position() &gt; 1]" mode="LogsData" /&gt; &lt;/xsl:for-each&gt; &lt;xsl:template match="Form/*" mode="LogsData"&gt; &lt;xsl:choose&gt; &lt;xsl:when test="name()='col0' and text()='Comments'"&gt; &lt;tr&gt; &lt;td&gt; &lt;b&gt; &lt;xsl:value-of select="name() = 'col0' and text()='comment'"/&gt; &lt;/b&gt; &lt;/td&gt; &lt;td&gt; &lt;xsl:for-each select="*[starts-with(name(), 'col')]"&gt; &lt;xsl:value-of select="." /&gt; &lt;/xsl:for-each&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/xsl:when&gt; &lt;xsl:otherwise&gt; &lt;tr&gt; &lt;xsl:for-each select="*[starts-with(name(), 'col')]"&gt; &lt;xsl:choose&gt; &lt;xsl:when test="name() = 'col0'"&gt; &lt;td&gt; &lt;b&gt; &lt;xsl:value-of select="." disable-output-escaping="yes"/&gt; &lt;/b&gt; &lt;/td&gt; &lt;/xsl:when&gt; &lt;xsl:otherwise&gt; &lt;td&gt; &lt;xsl:value-of select="." disable-output-escaping="yes"/&gt; &lt;/td&gt; &lt;/xsl:otherwise&gt; &lt;/xsl:choose&gt; &lt;/xsl:for-each&gt; &lt;/tr&gt; &lt;/xsl:otherwise&gt; &lt;/xsl:choose&gt; &lt;/xsl:template&gt; </code></pre> <p>The result is not generating as expected. The table is still coming the way it was. Separate TD for each comment data. I just want two TD in Comment section. First TD with "Comment" in it and second TD with all the other values of columns other then col0. Kindly help me to fix the issue. </p>