aspose file tools*
The moose likes XML and Related Technologies and the fly likes How to get XSL table with alternating  rows highlighted Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "How to get XSL table with alternating  rows highlighted " Watch "How to get XSL table with alternating  rows highlighted " New topic
Author

How to get XSL table with alternating rows highlighted

Rajitha Ereddy
Greenhorn

Joined: Nov 26, 2000
Posts: 20
Hi,
I have one more doubt in XSL if any one can help i would be thankful to you.Its like i have a table called transaction and the XML for that perticular table is as given:
<Transaction>
<TransactionDate>10/02/1999</TransactionDate>
<TransactionDescription>Interest paid</TransactionDescription>
<Sequence>Transaction Sequence Number</Sequence>
<Amount>50.00</Amount>
<Balance>2000.00</Balance>
</Transaction>

so for this table i want the xsl insuch a way that the alternate rows bgcolors should be diff like if even No: rows are blue in color i want the odd No: rows to be in yellow color so iam doing it using the position method but it is not working and my XSL goes like this:

<xsl:template match="Transaction">
<xsl:variable name="var">
<xsl:choose>
<xsl:when test=" position( ) mod 2 = 0">bgcolor=#FF6600</xsl:when>
<xsl therwise>bgcolor=#FFFFFF</xsl therwise>
</xsl:choose>
</xsl:variable>
<tr valign="top">
<xsl:attribute name="bgcolor"><xsl:value-of select="$var"/></xsl:attribute>
<td width="23%" align="center">
<xsl:value-of select="TransactionDate"/>
</td>
<td width="23%" align="center">
<xsl:value-of select="TransactionDescription"/>
</td>
<td width="23%" align="center">
<xsl:value-of select="Amount"/>
</td>
<td width="23%" align="center">
<xsl:value-of select="Balance"/>
</td>
<td width="40%">
<table border="0" cellspacing="1" cellpadding="1" width="677">
<tr>
<td width="103" height="21" bgcolor="#FFFFFF">
<xsl:value-of select="TransactionDate"/>
<font size="2" face="arial" color="#003366">
<xsl:value-of select="TransactionDate"/>
<xsl:text disable-output-escaping="yes">&nbsp;</xsl:text>
</font>
</td>
<td width="322" height="21" bgcolor="#FFFFFF">
<font size="2" face="arial" color="#003366">
<xsl:value-of select="TransactionDescription"/>
</font>
</td>
<td width="98" height="21" bgcolor="#FFFFFF">
<font size="2" face="arial" color="#003366">
<xsl:value-of select="Amount"/>
</font>
</td>
<td width="101" height="21" bgcolor="#FFFFFF">
<font size="2" face="arial" color="#003366">
<xsl:value-of select="Balance"/>
</font>
</td>
</tr>
<!--</xsl:for-each>-->
</table>
</td>
</tr>
</xsl:template>

So if possible can anyone tell how it can be achieved and i will be very thankful for that.Anyway thanks in advance.
Regards,
Rajitha.
prabhu palanisamy
Greenhorn

Joined: Oct 30, 2000
Posts: 27
use xsl:script to get alternate bg colors
regards
prabhu
Jane Griscti
Ranch Hand

Joined: Aug 30, 2000
Posts: 3141
Hi Rajitha,
Khun Yee Fung has an example of how to do this in his book XSLT: Working with XML and HTML

It works quite nicely.
Hope it helps.
------------------
Jane Griscti
Sun Certified Programmer for the Java� 2 Platform
[This message has been edited by Jane Griscti (edited March 09, 2001).]


Jane Griscti
SCJP, Co-author Mike Meyers' Java 2 Certification Passport
Rajitha Ereddy
Greenhorn

Joined: Nov 26, 2000
Posts: 20
Hi Jane Griscti,
Thanks for the code and its working.
Regards,
Rajitha.
Kamil Nishijima
Greenhorn

Joined: Jul 17, 2001
Posts: 1
I'm not getting this error
Unknown method. -->position()<-- mod 2 = 0
could I see the position function please?

[This message has been edited by Kamil Nishijima (edited July 17, 2001).]
Mapraputa Is
Leverager of our synergies
Sheriff

Joined: Aug 26, 2000
Posts: 10065
Old versions MSXML did not support all functions. Do you use Internet Explorer for XSLT transformation?


Uncontrolled vocabularies
"I try my best to make *all* my posts nice, even when I feel upset" -- Philippe Maquet
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to get XSL table with alternating rows highlighted
 
Similar Threads
Code Allignment In Xml Spy Editor
Make rows not appear when certain row value appears
JSP Page when submitted, List becomes empty
Html to database
JSP Help Regarding the Radio Button