[xsl] Conditional tagging in xsl:for-each

Subject: [xsl] Conditional tagging in xsl:for-each
From: Jan Eden <lists@xxxxxxxxxxx>
Date: Mon, 12 Dec 2005 21:30:55 +0100

I am new to XSLT, so please forgive me if this is a FAQ (I have found no
useful reference on the web). I have the following XML source (snippet):

        <child id="870">
            <title>Some text.</title>
        <child id="871">
            <title>More text</title>
        <child id="872">
            <title>Still more text.</title>

The children should be transformed into a two-column table. I tried this,
which makes the XSLT processors choke:

<xsl:template match="page[@type='galleries']/children">
    <xsl:for-each select="child">
        <td><img><xsl:attribute name="src"><xsl:value-of select="file"
/></xsl:attribute></img><xsl:value-of select="title" /></td>
        <xsl:if test="not(position() mod 2)"></tr><tr></xsl:if>

Obviously, they don't like the closing </tr> tag following my <xsl:if>. While
I see the reason for the error, I cannot find a way around it. Is there a way
to achieve what I want with XSLT?


There are 10 kinds of people:  those who understand binary, and those who

Current Thread