xsl-list
[Top] [All Lists]

every tenth row change bgcolor

2003-06-06 03:20:11

Ok, I've managed to get this far:

XML:

<?xml version="1.0" encoding="UTF-8"?>
<Report>

 <Row>white</Row>
 <Row>white</Row>
 <Row>white</Row>
 <Row>white</Row>
 <Row>white</Row>
 <Row>white</Row>
 <Row>white</Row>
 <Row>white</Row>
 <Row>white</Row>
 <Row>white</Row> <!-- 10 -->

 <Row>blue</Row>
 <Row>blue</Row>
 <Row>blue</Row>
 <Row>blue</Row>
 <Row>blue</Row>
 <Row>blue</Row>
 <Row>blue</Row>
 <Row>blue</Row>
 <Row>blue</Row>
 <Row>blue</Row> <!-- 20 -->

 <Row>white</Row>
 <Row>white</Row>
 <Row>white</Row>
 <Row>white</Row>
 <Row>white</Row>
 <Row>white</Row>
 <Row>white</Row>
 <Row>white</Row>
 <Row>white</Row>
 <Row>white</Row> <!-- 30 -->

</Report>

XSLT:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
<xsl:output method="html"/>
<!-- Root template of my stylesheet -->
   <xsl:template match="/">
     <html>
       <head>
          <title>Color rows</title>
        <style type="text/css">
        .r0 {background-color: white}
        .r1 {background-color: blue}
        </style>
       </head>
       <body>
        <table border="1">
        <xsl:apply-templates/>
        </table>
       </body>
     </html>
   </xsl:template>

   <xsl:template match="Row">
     <tr class="r{(floor(position() div 20) mod 2)}">
       <xsl:apply-templates/>
     </tr>
   </xsl:template>

</xsl:stylesheet>

Current result:
<html>
<head>
<META http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Cool XSLT App</title>
<style type="text/css">
        .r0 {background-color: white}
        .r1 {background-color: blue}
        </style>
</head>
<body>
<table border="1">

 <tr class="r0">white</tr>
 <tr class="r0">white</tr>
 <tr class="r0">white</tr>
 <tr class="r0">white</tr>
 <tr class="r0">white</tr>
 <tr class="r0">white</tr>
 <tr class="r0">white</tr>
 <tr class="r0">white</tr>
 <tr class="r0">white</tr>
 <tr class="r1">white</tr>

 <tr class="r1">blue</tr>
 <tr class="r1">blue</tr>
 <tr class="r1">blue</tr>
 <tr class="r1">blue</tr>
 <tr class="r1">blue</tr>
 <tr class="r1">blue</tr>
 <tr class="r1">blue</tr>
 <tr class="r1">blue</tr>
 <tr class="r1">blue</tr>
 <tr class="r0">blue</tr>

 <tr class="r0">white</tr>
 <tr class="r0">white</tr>
 <tr class="r0">white</tr>
 <tr class="r0">white</tr>
 <tr class="r0">white</tr>
 <tr class="r0">white</tr>
 <tr class="r0">white</tr>
 <tr class="r0">white</tr>
 <tr class="r0">white</tr>
 <tr class="r1">white</tr>

</table>
</body>
</html>


1. The question is that why in the first group is only 9 rows?

2. In this part : (floor(position() div 20) mod 2),
   Am I saying something like modulate the group of
   20 by 0 and 1 values? Quess not, but have to suggest something =)

Cheers,
Jarkko

****************************************************************
Jarkko Moilanen          "Erehtyminen on inhimillista,
Researcher                mutta todella suuret mokat
jm60697(_at_)uta(_dot_)fi            vaativat tietokoneen käyttöä."
www.uta.fi/~jm60697
GSM: +358 50 3766 927
****************************************************************
* ITCM | Information Technology and Crisis Management
* http://www.itcm.org
****************************************************************






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



<Prev in Thread] Current Thread [Next in Thread>