Complete Newbie Question on XSL Transform

A

Alan

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
 
P

Patrick TJ McPhee

[...]

% 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.
 

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. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top