unable to produce multiple rows in HTML td

351 views Asked by At

i tried to print td data on multiple rows, i'm using XSLT, basically if we do the following simple example:

<td rowspan="3">
  X
  Y
  z
</td>

the output will be as follows:

X Y Z

although i put the rowspan attribute the content still appears on one row !!

the real code is as follows:

<td width="800px" rowspan="3">
 <xsl:variable name='newline'><xsl:text>&#xa;</xsl:text></xsl:variable>
    <xsl:variable name="recip">
        <xsl:for-each select="page/message/recipients/recipient">
            <xsl:choose>
                <xsl:when test="position() mod 5 = 0">
                    <xsl:value-of select="concat(first-name,' ',middle-name,' ',last-name,$newline)"/>
               </xsl:when>
                 <xsl:otherwise>
                    <xsl:value-of select="concat(first-name,' ',middle-name,' ',last-name,',')"/>
                </xsl:otherwise>
           </xsl:choose>
        </xsl:for-each>
 </xsl:variable>
    <xsl:variable name="recipID">
<td/>

as i said although i print a new line using &#xa; the data remain appears on one line, any idea about fixing this problem?

2

There are 2 answers

0
Viridis On

You will always type from left to right in <TD>. If you actually do want linebreaks, use <br /> like you would everywher else.

For rowspan, read https://developer.mozilla.org/en-US/docs/Web/HTML/Element/td. I don't think it does what you think it does.

0
Mathias Müller On

I think you misunderstood the purpose of the rowspan attribute. This:

<td rowspan="3">

does not mean that the content of the element on which it is specified (td) is divided into three table cells. Rather, spanning multiple rows actually means that fewer cells are generated. In the above case, the resulting cell is as high as three "normal cells".

To illustrate this:

--------------------------------------------
| normal cell | normal cell |              |
-----------------------------              |
| normal cell | normal cell | cell with    |
----------------------------- rowspan="3"  |
| normal cell | normal cell |              |
--------------------------------------------

Now, in your stylesheet snippet, only one td element is being generated and it contains all the content that is output from within <td width="800px" rowspan="3">.

To output several table cells, write something along the lines of:

<xsl:for-each select="page/message/recipients/recipient">    
  <td><xsl:value-of select="first-name"/></td>
  <td><xsl:value-of select="middle-name"/></td>
  <td><xsl:value-of select="last-name"/></td>
</xsl:for-each>

Note that td elements must be nested inside a HTML table to be displayed correctly. (You did not show that part of your XSLT stylesheet).


UPDATE: If you understood all this, and really want to output three lines within one cell, this is how you can do it:

<td rowspan="3">X<br />Y</br />Z<br /></td>