Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

starting a new html table row with xslt

Status
Not open for further replies.

rubychyld

Programmer
Mar 22, 2001
76
US
I am trying to build a html table with xml data and start a new row with my xsl:if test=&quot;expression&quot; I am getting an error with the </td> tag. I surrounded the problem with stars. Any ideas how to get a new row here?

please help.
Liz

<xsl:template match=&quot;/&quot;>

<table class=&quot;navSelectedTable&quot; cellspacing=&quot;3&quot; width=&quot;100%&quot;>
<tr><td>

<xsl:for-each select=&quot;//Policy//MenuItem&quot;>

******************************error here (&quot;End tag 'td' does not match the start tag 'xsl:if'&quot;)
******************************
<xsl:if test=&quot;total &lt; 5&quot;>
</td></tr><tr><td
</xsl:if>
******************************

<a target=&quot;inquiries&quot; class=&quot;navItem&quot;>
<xsl:attribute name=&quot;href&quot;>
<xsl:value-of select=&quot;URL&quot; />
</xsl:attribute>
<xsl:value-of select=&quot;Display&quot; />
</a>

</xsl:for-each>

</td></tr>
</table>

</xsl:template>
 
if you look at the stylesheet from a purely xml point of view you'll see that it fails because you close a tag whilst a tag is still open.

essentially your doing

<td><xsl:if></td></xsl:if>

which is not allowed.

the solution will depend on whether the data is sorted and if so whether it's ordered across rows or down columns.

here is a suggestion, but not a solution :)

before you start the table you need to split your &quot;//Policy//MenuItem&quot;'s into 3 groups. the first group will contain the elements of the first row, the second group the second, and the third the third. so say there are now three xsl variables made with <xsl:variable name=&quot;firstcolumn&quot; select=&quot; &quot;/>

then you can use
<table>
<xsl:for-each select=&quot;$firstcolumn/Item&quot;>
<xsl:variable name=&quot;counter&quot; select=&quot;position()&quot;/>
<tr><td>
<xsl:value-of select=&quot;Item&quot;/>
</td>
<td>
<xsl:value-of select=&quot;$secondcolumn[$counter]/Item&quot;/>
</td>
<td>
...
</tr>
</tr>
</xsl:for-each>
</table>

so each pass of the for-each makes each row and we keep track of where we are with $counter.
i'm not sure what would happen if the original group size is not a multiple of three, making us call $thirdrow[10] when maybe it doesn't exist.

making each of the groups is not that easy either. <xsl:variable name=&quot;thirdcolumn&quot; select=&quot;Item[position() div 3 = 0]&quot;/>

dunno if that's legal use of xpath.

hope this helps in some way :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top