473,395 Members | 1,885 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

formating row color equal if node names are Equal

4
Hi all,

I am a bit desperate already trying to display a XML file using XSLT. I create a table and use <xsl:for-each> to extract every element node. This is working fine. What I want now is so format every column with a color (e.g. red) if the element value is the same as the one in the next node. if the value changes if should change the color (e.g. to blue) and stay so long blue as the value is the same. With the next change, I should switch back to red.
The problem is that I can't find a way to memorize the value of the "old" color.

I give you the shot example which makes is hopefully more clear.

XML file

<node name="first">
<type>1 for test purpose</type>
<user>Paul</user>
</node>

<node name="second">
<type>2 for test purpose</type>
<user>Paul</user>
</node>

<node name="third">
<type>3 for test purpose</type>
<user>Joe</user>
</node>

<node name="fourth">
<type>4 for test purpose</type>
<user>Jenny</user>
</node>

<node name="fith">
<type>5 for test purpose</type>
<user>Jenny</user>
</node>

XSL
<xsl:template match="/">
<html xmlns="http://www.w3.org/1999/xhtml">
<head></head>
<body>
<table border="1">
<tr><td><b>Nodename</b></td>
<td><b>type</b></td>
<td><b>user</b></td>
</tr>
<xsl:for-each select="node">
<tr><td><xsl:value-of select="@name"/></td>
<td><xsl:value-of select="type"/></td>
<td><xsl:apply-templates select="user"/></xsl:when>
</td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>


<xsl:template match="user">



<xsl:variable name="before" select="preceding::node[1]/url" />
<xsl:variable name="after" select="following::node[1]/url" />
<xsl:variable name="new" select="." />

<xsl:if test="$after != $new">
<xsl:variable name="newcolor" select="1">
</xsl:variable>
<xsl:call-template name="urlcolor">
<xsl:with-param name="counter" select="$newcolor" />
</xsl:call-template>
</xsl:if>


<xsl:if test="$after = $new">
<xsl:variable name="newcolor"><xsl:text>0</xsl:text></xsl:variable>

<xsl:call-template name="urlcolor">
<xsl:with-param name="counter" select="$newcolor + 1" />
</xsl:call-template>
</xsl:if>
</xsl:template>

<xsl:template name="urlcolor">
<xsl:param name="counter" />

<xsl:if test="$counter = 1">
<div style=" color:#000000; font-style:bold; background-color:#33CC33">
<xsl:value-of select="." />
</div>
</xsl:if>
<xsl:if test="$counter = 2">
<div style=" color:#000000; font-style:bold; background-color:#FFCC33">
<xsl:value-of select="." />
</div>
</xsl:if>
</xsl:template>
</xsl:stylesheet>

It doesn't work now but it should give the user "Paul" the red color(for 2 rows), Joe blue (one row), Jenny again red (2 rows)

Please help.

Thanks a lot
Jan 21 '07 #1
0 3354

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Alex | last post by:
Hello, I don't have sufficient experience with XSLT, and would really appreciate somebody's help in me giving ideas on solving a problem I have. Let's consider the following XML file: ...
0
by: Phl | last post by:
hi, does any know why my javascript dropdownlist in my user control will only appear if I have my code as follows: // create an instance of the user control Control UCAdminDDMenu =...
2
by: Tim::.. | last post by:
Hi I'm trying to create a pager that allows you to show records by year and month! I am getting close but would really appritiate some help! Can someone please tell me how I convert the value of...
7
by: Piper707 | last post by:
Hi, I need to know how I can check to see if a particular node is NOT equal to a SET of values. i.e. a valid form of : <xsl:template match!="H" && match!="Y"&& match!="Z"> I have an XML...
8
by: GHUM | last post by:
imagine: template=""" Hello %(name)s, how are you %(action)s""" we can use it to do things like: print template % dict (name="Guido", action="indenting")
2
by: naima.mans | last post by:
Hello, i want to select 2 following brothers nodes wich are one under another (one closed to another)... i have done one xslt file... but it's not really good.. for example: the xml file:...
1
by: Shawn Northrop | last post by:
I just read an article on kirupa.com about incorporating mySQL and PHP with flash. I am dynamically loading conent into a flash movie and am not sure how to format. In my php code i have: $y = "";...
1
by: Falcula | last post by:
Hello, I have a treeview control, when i select a item i navigate to url. But selected node is lost, it reset itself, loosing state. I post my code here. Thanks in advance. <script...
3
by: sudhivns | last post by:
Hi, following is the part of my xml file. data.xml <Value> This is normal text This has to be printed in bold. This has to be printed in Italic. This has to be printed in bold/italic.
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.