Re: [xep-support] "Filtered" Select and alternating background-color

From: Volodymyr Mykhailyk <>
Date: Thu May 25 2006 - 06:43:59 PDT
as for me, the most easier way to fix this:
It will not cause any performance issues and possible failures with big variables or recursions.
    <xsl:apply-templates select="article[1]" mode="someMode">
        <xsl:with-param name="count" select="1"/>

<xsl:template match="article" mode="someMode">
    <xsl:param name="count"/>
       <xsl:when test="all_condition_that_you_have">
            <fo:table-row page-break-inside="avoid">
<xsl:if test="($count mod 2) = 0">
<xsl:attribute name="background-color">some_color</xsl:attribute>
             <xsl:apply-templates select="following-sibling::article[1]" mode="someMode">
                <xsl:with-param name="count" select="$count+1"/>
           <xsl:apply-templates select="following-sibling::article[1]" mode="someMode">
              <xsl:with-param name="count" select="$count"/>
In other word: it process articles one after another, and if conditions are true it give another template parameter count increased by one point.
"someMode" in apply-templates used in case if you have special processing of article in another place.
Powell, Todd wrote:
Hi Martin,

Personally, I see "recursion solutions" as a kind of a workaround for
one of XSLT's shortcomings -- namely no traditional variables -- and
they make it difficult to understand what's going on in the script (if
not for the original developer, then for any subsequent support staff
trying to take over maintenance).

AND, if you ARE talking about a really huge table, and it causes your
transformation "to exlode" (nice imagery Geoff :-), then you can't use
it at all.

I'd suggest two alternatives:

1) If you are using a parser that supports javascript scripting as
callable functions from the XSL (Microsoft's is one), you could create a
"global" javascript variable that truly does get incremented during each
table row output, and whose value can be queried to determine odd/even;

2) Split your XSLT process into two distinct passes:  one which
sorts/filters/etc. the data into the desired order, and another which
operates on the result of the first and simply looks at the (position()
mod 2) to determine odd/even.

Each of these options have their downsides, and may prove undoable for
your situation, but I think they are more straightforward in their logic
than the recursive approach.

Hope this helps!


Todd S. Powell
Project Performance Corporation
Principal Analyst
U.S. Department of Energy

David Pirkle schrieb:
You could try moving the body of your loop into a recursive template,
and then replace the for-each with a call to the template.  That 
would allow you to have a variable that increments for each element 
that passes the filter, and you could use the modulus test on that.

-----Original Message-----
Martin Snajdr|AMAN
Sent: Tuesday, May 23, 2006 1:16 AM
Subject: [xep-support] "Filtered" Select and alternating

Hi there,

i have a problem with a real huge table, which has to have
alternating background-color in each table-row.
As you can see in the following excerpt, i have to use a xsl:if to 
filter the select. But doing it this way prevents the 
position()-thing from working right, when the filter is active.

<xsl:for-each select="article">
	<xsl:if test="(($filter_material='all') or
				and (($filter_knaggen='all') or
($filter_knaggen!='all' and 
				and (($filter_nenngroesse='all') or

				and (($filter_eingang='all') or
($filter_eingang!='all' and
	<fo:table-row page-break-inside="avoid">
	<xsl:attribute name="background-color"><xsl:if test="position()
test="position() mod 2 != 0">rgb-icc(227, 231,

I tried to change the select to do the filtering, but since the
filter depends on passed-in params i'm not able to do this. I tried 
some exslt node-set-stuff, but i didn't get to it.

Anyone any idea?

(*) To unsubscribe, send a message with words 'unsubscribe xep-support'
in the body of the message to from the address
you are subscribed from.
(*) By using the Service, you expressly agree to these Terms of Service


------------------- (*) To unsubscribe, send a message with words 'unsubscribe xep-support' in the body of the message to from the address you are subscribed from. (*) By using the Service, you expressly agree to these Terms of Service Received on Thu May 25 07:12:50 2006

This archive was generated by hypermail 2.1.8 : Thu May 25 2006 - 07:12:52 PDT