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

Re: alternate row color in a table

Subject: Re: alternate row color in a table
From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx>
Date: Thu, 14 Feb 2002 14:57:03 +0000
row color table
Hi Sébastien,

> ***XML***
> <?xml version="1.0" encoding="UTF-8"?>
> <?xml:stylesheet type="text/xsl" href="simple4.xsl"?>
> <data>
> <info>aaaaa</info>
> <info>bbbbb</info>
> <grinfo><info>ccccc</info></grinfo>
> <grinfo><subinfo>blabla</subinfo><info>ddddd</info></grinfo>
> </data>
[snip]
> the row with ccccc and the row with ddddd have the same bgcolor
> using position() in this case seems to work just with siblings.

Actually, the position() function works on the list of nodes that you
*select* to process, and that can make it look as though it just works
on siblings.

In your template for the data element:

<xsl:template match="data">
  <table><xsl:apply-templates/></table>
</xsl:template>

to get the content of the table, you apply templates to all the child
nodes of the data element. There are actually nine child nodes for the
data element in your example: two info elements, two grinfo elements,
and between the elements five whitespace-only text nodes (each
containing a line break so that the elements start on different
lines). The positions of these nine nodes are 1, 2, 3, ..., 8, 9.

Because of the whitespace, the two info elements have the position 2
and 4.

The other info elements that you're interested in are within the
grinfo elements. The template for the grinfo elements is simply:

<xsl:template match="grinfo">
  <xsl:apply-templates/>
</xsl:template>

Fortunately, there's no whitespace to worry about, but the other
subinfo element in the second grinfo element does make a difference.
So the info element in the first grinfo element has a position of 1.
And the info element in the second grinfo element has a position of 2.

So the positions you end up with for the info elements are 2, 4, 1, 2.
To get the info elements to have the right positions (and therefore to
get your alternate colouring to work), you need to process the info
elements such that their positions are 1, 2, 3, and 4. In other words,
you need to process a node set that just contains the four info
elements.

You can get hold of the four info elements that you're interested in
from the template matching the data element with the location path:

  .//info

(Or you could use info | grinfo/info, but I'm guessing that your real
source data is slightly more complicated than your sample, and the
info elements might appear at any level.)

The template for the data element, then, should look like:

<xsl:template match="data">
  <table><xsl:apply-templates select=".//info" /></table>
</xsl:template>

And you can get rid of the template matching grinfo elements since it
will never be used.

Making that change should make the template for the info elements
work.

Cheers,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/


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


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

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.
Email
First Name
Last Name
Company
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.