Altova Mailing List Archives>Archive Index >microsoft.public.xsl Archive Home >Recent entries >Thread Prev - How to build a tlabe? [Thread Next] Re: How to build a tlabe?To: NULL Date: 6/4/2006 10:18:00 PM
"anotherron" <anotherron@d...> wrote in message
news:570125D8-57F8-4075-BAAC-A39AB2A93C1D@m......
> I am trying to build a 2-column table but am getting errors. The code that
I
> am using is similar to:
>
> <table>
> <xsl:for-each match="parent">
> <xsl:if test="position() mod 2 = 1">
> <tr>
> </xsl:if>
> <td>
> <xsl:apply-templates match="child"/>
> </td>
> <xsl:if test="position() mod 2 = 0")
> </tr>
> </xsl:if>
> </xsl:for-each>
> </table>
>
> The error refers to the <tr> line and states that there is no
corresponding
> </tr>. I see why this is an error, but I do not know how to correct the
> problem. Any help will be greatly appreciated.
This is my stock template xsl of the solution to this sort of problem:-
<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" encoding="UTF-8" />
<xsl:param name="cellCount" select="2" />
<xsl:template match="items">
<table rules="all">
<xsl:for-each select="item[position() mod $cellCount = 1]">
<tr>
<xsl:for-each select=". | following-sibling::item[position() <
$cellCount]">
<td><xsl:value-of select="." /></td>
</xsl:for-each>
</tr>
</xsl:for-each>
</table>
</xsl:template>
</xsl:stylesheet>
Assumes a very simple input of
<items>
<item>1</item>
<item>2</item>
.
.
.
<item>n</item>
</items>
It works by using an outer for each for items that would be in the first
column.
Then uses an inner for each selecting this node and any following sibiling
up to the number items needed for a complete set of cells for a row.
This solution works for pre-ordered items. If you also need xsl:sort then
this general solution isn't applicable.
Anthony.
| ||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
