[XSL-LIST Mailing List Archive Home]
[Reply To This Message]
Re: Selecting similar XML nodes by a sort criteria
Subject: Re: Selecting similar XML nodes by a sort criteria|
From: Wendell Piez <wapiez@xxxxxxxxxxxxxxxx>
Date: Thu, 04 Oct 2007 14:45:34 -0400
It seems to me that (in the example given) your color criterion is
simply the areacode itself. When areacode is odd, the color is grey;
when it's even, the color is blue.
If so, this is easily determined by testing (@areacode mod 2): when
is is 1 (or has Boolean value "true") make it one color, when it is 0
(or Boolean false) make it the other.
This won't work, however, if your areacode values are not perfectly
in series. That is, say you want blue/gray/blue/gray for areacode
values 1/2/4/5, since you happen to have no value 3. Or your
areacodes come with any arbitrary set of values not liable to such testing.
In this case, things are more complicated. Let us know if this is a
possibility, and if so, whether you can use XSLT 2.0 (much easier) or
are restricted to using 1.0 (not as easy), and if the latter, whether
extension functions are allowable.
(This *can* be done in unextended XSLT 1.0 but I wouldn't wish it on
a friend -- with the exception of some friends on this list, who have
been known to find this sort of thing entertaining.)
At 01:41 PM 10/4/2007, you wrote:
I have the following XML. I would like to write XSLT which outputs the
above XML in an HTML table. This table should be sorted by 'areacode'.
<?xml version="1.0" encoding="ISO-8859-1"?>
<title lang="eng">Harry Potter</title>
<title lang="eng">Learning XML</title>
<title lang="eng">Count of Monte Cristo</title>
<title lang="eng">Tom Sawyer</title>
This part is fine. The problem comes when I try to color the rows in the
table so that the rows with the same areacode are the same color and the
colors alternate for rows that are not the same area code e.g. I have 2
row colors, gray and blue. This is what the HTML should look like(sorry
about the poor HTML markup, this is just for illustration):
<td>Count of Monte Cristo</td>
What I tried was after doing something like (pseudocode):
write out the html row
I need some logic or pseudocode which I can insert in the line marked
(-----) so that it would selectively apply the style attribute with the
appropriate color with each row.
I am hoping that my question is clear enough. But I could also write the
full XSLT if that would help. I made up this example, so I don't have
the XSLT code for this particular example.
Does anyone know of any XSLT or XPath function I could use.
I am trying to use the XPath axes preceding-sibling. But its not working
Wendell Piez mailto:wapiez@xxxxxxxxxxxxxxxx
Mulberry Technologies, Inc. http://www.mulberrytech.com
17 West Jefferson Street Direct Phone: 301/315-9635
Suite 207 Phone: 301/315-9631
Rockville, MD 20850 Fax: 301/315-8285
Mulberry Technologies: A Consultancy Specializing in SGML and XML
PURCHASE STYLUS STUDIO ONLINE TODAY!
Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!
Download The World's Best XML IDE!
Accelerate XML development with our award-winning XML IDE - Download a free trial today!
Subscribe in XML format