[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Conditional tagging in xsl:for-each

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

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):

    <children>
        <child id="870">
            <file>dscn1095.jpg</file>
            <title>Some text.</title>
        </child>
        <child id="871">
            <file>dscn1100.jpg</file>
            <title>More text</title>
        </child>
        <child id="872">
            <file>dscn1101.jpg</file>
            <title>Still more text.</title>
        </child>

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">
    <table><tr>
    <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>
    </xsl:for-each>
    </tr></table>
</xsl:template>

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?

Thanks,

Jan
--
There are 10 kinds of people:  those who understand binary, and those who
don't

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.