473,699 Members | 2,531 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

XSL Help - Alternate row colour without being able to use position()

I have a need to alternate output row colour where not every row in the
sequence is output, so I cannot base the colour on whether position() is odd
or even.
e.g.
....
<xsl:for-each select="result" >
<xsl:if test="@status = 'Pass'">
<tr><td>@name </td></tr>
</xsl:if>
<xsl:for-each>
....

Any helpful suggestions would be welcome.

--
Matt B
Oct 10 '05 #1
7 5989
rayt
7 New Member
Combine the if with the select then you can choose odd and even.

<xsl:for-each select="result[@status = 'Pass']">

Ray
Oct 10 '05 #2

"Matt B" <ma************ @london.com> wrote in message
news:43******** *************** @news.sunsite.d k...
I have a need to alternate output row colour where not every row in the
sequence is output, so I cannot base the colour on whether position() is
odd or even.
e.g.
...
<xsl:for-each select="result" >
<xsl:if test="@status = 'Pass'">
<tr><td>@name </td></tr>
</xsl:if>
<xsl:for-each>
...

Any helpful suggestions would be welcome.


A pure XSLT 1.0 solution:
This shows how to create a N-column table from the nodes of a node-set.
N and the node-set are passed as parameters.
No extension function is referenced (and no "following-sibling"
axis is used)
The rows are displayed in alternate colours.
http://www.topxml.com/code/default.a...20020514091249
Hope this helped.
Cheers,
Dimitre Novatchev
Oct 10 '05 #3
Matt B wrote:
I have a need to alternate output row colour where not every row in the
sequence is output, so I cannot base the colour on whether position() is odd
or even.


You can. Something like:

<xsl:apply-templates select="result[@status='Pass']"/>

....

<xsl:template s match="result">
<tr>
<xsl:if test="position( ) mod 2 = 1">
<xsl:attribut e name="class">od d</xsl:attribute>
</xsl:templates>
<!-- something --->
</tr>
</xsl:templates>

--
Johannes Koch
Spem in alium nunquam habui praeter in te, Deus Israel.
(Thomas Tallis, 40-part motet)
Oct 10 '05 #4
"Dimitre Novatchev" <di******@tpg.c om.au> wrote in message
news:43******** *************** @authen.white.r eadfreenews.net ...

"Matt B" <ma************ @london.com> wrote in message
news:43******** *************** @news.sunsite.d k...
I have a need to alternate output row colour where not every row in the
sequence is output, so I cannot base the colour on whether position() is
odd or even.


A pure XSLT 1.0 solution:
This shows how to create a N-column table from the nodes of a
node-set.
...
Hope this helped.


Yes, very useful.
Thanks.

--
Matt
Oct 11 '05 #5
"Johannes Koch" <ko**@w3develop ment.de> wrote in message
news:43******** *************** @authen.white.r eadfreenews.net ...
Matt B wrote:
I have a need to alternate output row colour where not every row in the
sequence is output, so I cannot base the colour on whether position() is
odd or even.


You can. Something like:

<xsl:apply-templates select="result[@status='Pass']"/>


I was hoping for something which didn't rely on *all* rows having to be
output. There may be an extra selection or decision within the main
selection which means some rows aren't used. An independent toggling
solution would be very useful.

--
Matt
Oct 11 '05 #6
rayt
7 New Member
All Rows would not be passed to output using the solution by Johannes

<xsl:apply-templates select="result[@status='Pass']"/>

....

<xsl:template s match="result[@status='Pass']"/>
<tr>
<xsl:if test="position( ) mod 2 = 1">
<xsl:attribut e name="class">od d</xsl:attribute>
</xsl:templates>
<!-- something --->
</tr>
</xsl:templates>

Is the problem due to the non pass nodes being processed by the default template. If so add a bit bucket template eg

<xsl:apply-templates select="result"/>

If this is the case result nodes with a status of pass will be processed into the output tree by Johannes template . Non pass nodes will hit the bit bucket and not pass through.

If you mean something else could you give some test XML and an example of your target output.

You appear to be insisting on having an if within a for-each but this is carried out by the predicate [@status='Pass'] don't forget you can use multiple predicates by joining with and's and or's so any extra selection or decision can be made within the select statement. Also nodesets can be passed around with variables. Give some examples of what you need.
Oct 11 '05 #7
rayt
7 New Member
I just noticed that in Johannes template the apply-templates does not implicitly tie in with the template. In the posting above notice how the predicate is applied to the apply-template select and the the template match clauses. Another way is to tie the two together by using mode.

Ray
Oct 11 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
4573
by: Alistair Birch | last post by:
Hi I want rows of a table to appear in alternating background colours. Having looked around the web I can't find any solution apart from waiting for the next version of CSS, so I tried building one myself, but I need some help to finish it. I use the getAttribute('rowIndex') to return the position of a row within the table and apply modulo 2 to return a 0 or 1 indicating an even or odd row number, from which I apply the alternating...
4
2454
by: Werner Partner | last post by:
I'm looking for something like that: http://www.sonoptikon.de/praxis-mt/test.php The text should have a certain indent, and from the left border should come a "marker" which goes over the text for a certain length. Please don't look at the source text, ;-) it's terrrible, but I just wanted to show how about it should look like. Of course in my test case I cannot realize two features: - the couloured marker should always have same...
1
4637
by: news | last post by:
Hi all, How do you implement alternate line colors in ms access datasheet view Regards Joe --- Outgoing mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.512 / Virus Database: 309 - Release Date: 20/08/2003
4
2281
by: sconeek | last post by:
Hi all, I am generating a html based table with multiple rows of data coming in real time from a postgres DB. The underlying technology is java based however the front end is html. now i am unable to alternate the colour of every row so that the table is lot more readable. can anyone suggest a javascript or even a css script which will alternate the row colours irrespective of the number of rows.
6
2424
by: sconeek | last post by:
hi all, my java servlet code has a foreach loop which automatically generates a HTML table with x number of rows. now my problem is that I would like the rows to be alternating in colour so that its a lot more easier to read. i have tried to implement a few approaches but everytime it fails. can somebody help me out with us and suggest a solution. thanks.
3
3612
by: Johny | last post by:
I use PIL to write some text to a picture.The text must be seen wery clearly. I write the text to different pictures but to the same position. As pictures maybe different, colour, in the position where I write the text, is also different. Is there a way how to set the font colour so that it will be seen very clearly in the picture? For example, if the picture is bright ( for example yellow), the font colour should be dark( e.g. black)...
4
3720
by: Johny | last post by:
I use PIL to write some text to a picture.The text must be seen wery clearly. I write the text to different pictures but to the same position. As pictures maybe different, colour, in the position where I write the text, is also different. Is there a way how to set the font colour so that it will be seen very clearly in the picture? For example, if the picture is bright ( for example yellow), the font colour should be dark( e.g. black)...
3
2195
by: Charles Law | last post by:
Ok. I haven't been around for a while, so I hope someone will come to my rescue. I thought I had done this years ago, but I have scoured my code snippets and can't find it. I want my ListView control to have a different background colour on alternate rows. I'm using VS2005. Firstly, I'm surprised that I can't do it out of the box. But secondly, I can't find a really simple one-liner that let's me do it by overriding something.
18
4366
by: JohnDriver | last post by:
Hi, I am happy to say that with your help, I have been performing good in Ajax. Thanks for helping me to start with. I have a small problem now. I am pulling records from database and passing result of the query in a table. I would like some help with the code to colour the alternate rows please. function printQuery($param) { echo "<table width=100% valign=center>"; echo "<tr>"; foreach ($param as $key => $result)
0
8691
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9180
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9038
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
7755
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6536
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4633
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3060
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2351
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2012
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.