473,748 Members | 10,889 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 5996
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
4575
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
2464
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
4640
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
2282
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
2427
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
3614
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
3722
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
2196
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
4368
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
8830
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9541
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
9370
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
9247
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6796
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
6074
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4602
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4874
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3312
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

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.