Complete Newbie Question on XSL Transform

Discussion in 'XML' started by Alan, Jul 11, 2004.

  1. Alan

    Alan Guest

    Hi,

    Although an experienced programmer I am totally newto XML/XSL and in good
    old style I'm trying to pick it up from various examples. I found one nice
    e.g. that produced a basic table from a recordset produced XML document,
    However what I would like to do is have each alternate line in the table
    have a different colour the <TR> part of the XSL is

    <xsl:template match="z:row">
    <TR>
    <xsl:for-each
    select="/xml/s:Schema/s:ElementType[@name='row']/s:AttributeType">
    <xsl:choose>
    <xsl:when test="@rs:hidden" />
    <xsl:when test="/xml/layout/field[@name $ieq$
    context(-1)/@name]/@visible[text() $ieq$ 'false']"/>
    <xsl:eek:therwise>
    <td nowrap='true'>
    <xsl:choose>
    <xsl:when test="s:datatype/@dt:type[text() = 'string']"/>
    <xsl:eek:therwise>
    <xsl:attribute name="align">right</xsl:attribute>
    </xsl:eek:therwise>
    </xsl:choose>
    <xsl:apply-templates
    select="context(-2)/@*[nodeName()=context(-1)/@name]" />

    </td>
    </xsl:eek:therwise>
    </xsl:choose>
    </xsl:for-each>
    </TR>
    </xsl:template>

    Is there a way to work out if the row is odd or even and then apply a class
    to the row based on the result.
    Thanks
     
    Alan, Jul 11, 2004
    #1
    1. Advertisements

  2. [...]

    % However what I would like to do is have each alternate line in the table
    % have a different colour the <TR> part of the XSL is

    Use the position() function and mod operator. Something like

    <xsl:if test='position() mod 2'>colour-spec</xsl:if>

    note that position() doesn't always do what you want at the template
    level, but generally does within a for-each loop.
     
    Patrick TJ McPhee, Jul 11, 2004
    #2
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.