[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: how to increment a variable in a for-each loop

Subject: Re: how to increment a variable in a for-each loop
From: Wendell Piez <wapiez@xxxxxxxxxxxxxxxx>
Date: Wed, 23 Jan 2002 18:43:09 -0500
xsl for loop increment

Your xsl:for-each is throwing you off. It's just selecting the current node; but since it is, position() is always 1.

Try it without. If position() is still getting thrown off (which could be happening if you are processing nodes you haven't accounted for -- for example, whitespace-only text nodes in your source which you can only see if you know how to look for them), then try using, instead,


which is more robust than position() for these purposes; or alternatively make sure the apply-templates that is getting you this template is constructed to select just the nodes you want (probably the best solution).

If this is unclear, we can explain it better if we see both some source data, and the template(s) one step "above" this template (i.e. where elements are selected to which this template matches -- i.e. the one that says mode="diff_cols"). Concrete examples make discussion easier. :-)

Good luck,

At 06:14 PM 1/23/02, you wrote:
I have a code snippet as below:
<xsl:template match="*" mode="diff_cols">
<xsl:for-each select=".">
    <xsl:if test="position() mod 2 = 1">
        <fo:table-cell  background-color="red">
<fo:block><xsl:value-of select="."/></fo:block>
    <xsl:if test="position() mod 2 = 0">
        <fo:table-cell  background-color="blue">

Unfortunately, it did not work.  The background color
in all columns is red.

Can you help to debug?

Wendell Piez                            mailto:wapiez@xxxxxxxxxxxxxxxx
Mulberry Technologies, Inc.                http://www.mulberrytech.com
17 West Jefferson Street                    Direct Phone: 301/315-9635
Suite 207                                          Phone: 301/315-9631
Rockville, MD  20850                                 Fax: 301/315-8285
  Mulberry Technologies: A Consultancy Specializing in SGML and XML

XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list

Current Thread


Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
First Name
Last Name
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.