Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: How to build a tlabe?

From: "Anthony Jones" <Ant@------------.--->
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() &lt;
$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.




transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent