XSL Help - Alternate row colour without being able to use position()

M

Matt B

I have a need to alternate output row colour where not every row in the
sequence is output, so I cannot base the colour on whether position() is odd
or even.
e.g.
....
<xsl:for-each select="result">
<xsl:if test="@status = 'Pass'">
<tr><td>@name</td></tr>
</xsl:if>
<xsl:for-each>
....

Any helpful suggestions would be welcome.
 
D

Dimitre Novatchev

Matt B said:
I have a need to alternate output row colour where not every row in the
sequence is output, so I cannot base the colour on whether position() is
odd or even.
e.g.
...
<xsl:for-each select="result">
<xsl:if test="@status = 'Pass'">
<tr><td>@name</td></tr>
</xsl:if>
<xsl:for-each>
...

Any helpful suggestions would be welcome.

A pure XSLT 1.0 solution:
This shows how to create a N-column table from the nodes of a node-set.
N and the node-set are passed as parameters.
No extension function is referenced (and no "following-sibling"
axis is used)
The rows are displayed in alternate colours.


http://www.topxml.com/code/default.asp?p=3&id=v20020514091249


Hope this helped.


Cheers,
Dimitre Novatchev
 
J

Johannes Koch

Matt said:
I have a need to alternate output row colour where not every row in the
sequence is output, so I cannot base the colour on whether position() is odd
or even.

You can. Something like:

<xsl:apply-templates select="result[@status='Pass']"/>

....

<xsl:templates match="result">
<tr>
<xsl:if test="position() mod 2 = 1">
<xsl:attribute name="class">odd</xsl:attribute>
</xsl:templates>
<!-- something --->
</tr>
</xsl:templates>
 
M

Matt B

Dimitre Novatchev said:
A pure XSLT 1.0 solution:
This shows how to create a N-column table from the nodes of a
node-set.
...
Hope this helped.

Yes, very useful.
Thanks.
 
M

Matt B

Johannes Koch said:
Matt said:
I have a need to alternate output row colour where not every row in the
sequence is output, so I cannot base the colour on whether position() is
odd or even.

You can. Something like:

<xsl:apply-templates select="result[@status='Pass']"/>

I was hoping for something which didn't rely on *all* rows having to be
output. There may be an extra selection or decision within the main
selection which means some rows aren't used. An independent toggling
solution would be very useful.
 

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

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,014
Latest member
BiancaFix3

Latest Threads

Top