Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Alternate actions on looping

Status
Not open for further replies.

Crundy

Programmer
Jul 20, 2001
305
GB
Hello,
I'm new to XML, so forgive me if this seems dumb!!

I'm trying to build a table using values from my XML file with alternating row background colors. I've tried:

<xsl:param name=&quot;skip&quot; select=&quot;1&quot;/>

<xsl:for-each select=&quot;dept&quot;>
<TR><xsl:attribute name=&quot;bgcolor&quot;>
<xsl:if test=&quot;$skip=1&quot;>
#ffffff
</xsl:if>
<xsl:if test=&quot;$skip=0&quot;>
#f0f0fd
</xsl:if>
</xsl:attribute>
<xsl:if test=&quot;$skip=1&quot;>
<xsl:with-param name=&quot;skip&quot; select=&quot;0&quot;/>
</xsl:if>
<xsl:if test=&quot;$skip=0&quot;>
<xsl:with-param name=&quot;skip&quot; select=&quot;1&quot;/>
</xsl:if>
etc

but Saxon tells me I can't use 'with-param' from within an 'if' node. I tried using 'when' and 'otherwise' instead of an if, but got the same error.

Can anyone help? C:\DOS:>
C:\DOS:>RUN
RUN DOS RUN!!

If this post was useful to you, click the link below
 
the <xsl:with-param> element is used when calling templates and so must be inside a <xsl:apply-templates> or <xsl:call-template>.
i can't really see what your solution would be tho. if $skip=1, what should the output look like?
 
What it should do is go through the loop once and make <tr> followed by all the data for that row and a </tr> (not shown), then loop to the beginning, but this time make a <tr bgcolor=&quot;#f0f0fd&quot;>. C:\DOS:>
C:\DOS:>RUN
RUN DOS RUN!!

If this post was useful to you, click the link below
 
It's ok, I've solved my own problem!!
If anyone's interested, this is how I did it:

<tr><xsl:attribute name=&quot;bgcolor&quot;>
<xsl:choose>
<xsl:when test=&quot;position() mod 2=0&quot;>#f0f0fd</xsl:when>
<xsl:eek:therwise>#ffffff</xsl:eek:therwise>
</xsl:choose>
</xsl:attribute>
C:\DOS:>
C:\DOS:>RUN
RUN DOS RUN!!

If this post was useful to you, click the link below
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top