Re: alternating tags in a list?

Subject: Re: alternating tags in a list?
From: "Michael Los" <mel@xxxxxxxxx>
Date: Fri, 11 Dec 1998 08:11:04 -0500
I am very interested in seeing how to produce alternating patterns without
scripting.  Anyone have a short example?

We are using XSL stylesheets written in acccordance with the XSL Proposal
(the wd draft didn't exist at the time) in a phonebook-type application.  A
query to the application results in an HTML page that may contain multiple
entries. Each entry is formatted as an HTML table with either a white or
gray background.  To accomplish this, we used the method described by Guy
using ECMAScript.

My two comments:
1. I don't think the need to alternate is a rare occurrence as Guy suggested
it might be.  I anticipate that the need to identify the nth item and do
something based on that condition will be fairly frequent.

2. I hope that support for scripting (preferably, user-specified, such as
<define-script lang="ECMAScript">...</define-script> makes it back into the
XSL Spec. (P.S. I understand the consequences of lang= and how it doesn't
necessarily allow a style sheet to work with all XSL processors. Specify one
that all must support and let the market go from there.)

Michael Los
The MITRE Corporation


Date: Thu, 10 Dec 1998 17:29:31 +0000
From: Guy_Murphy@xxxxxxxxxx
Subject: Re: alternating tags in a list?

Well sort of thinking out loud as it where...

You can evaluate conditions in XSL. As long as you can determine the index
of the current tag then you can produce alternating patterns by dividing by
your factor and checking the remainder, if it equals 0, it's the first of
sequence, 1 second in sequence and so on.

So you don't need to track state, just obtain index, evaluate a condition,
and perform basic arithmetic. You could do this without resorting to
script, but it would probably be more concise with script. It would IMHO be
a pity not to include script for these matters as it would mean bending the
simple XSL out of shape to occomodate these rare occurences. Such matters
are best expressed in a procedural language sniper, ie. a piece of script.

I've used this method many times when transforming data to HTML via ASP.

Personaly, if W3C doesn't include ECMAScript support in the final Rec I'll
be using the non-compliant variety of parser that does :)



xsl-list@xxxxxxxxxxxxxxxx on 12/10/98 06:16:26 PM

To:   xsl-list@xxxxxxxxxxxxxxxx
cc:    (bcc: Guy Murphy/UK/MAID)
Subject:  alternating tags in a list?




I think that's beyond the scope of XSL per se. To handle odd/even, you
either need a richer styling language, or you need some way to extend XSL.
Some early versions of XSL did have some ability to invoke a procedural
language such as ECMAscript, which could provide the "state" information
for this kind of toggling...
It occurs to me that what you probably _really_ want is not 2 columns, but
N columns, where N is chosen to suit the width of the presentation medium
and where the items are flowed from line to
line to fill out that width. Might be hard to express that in HTML... Do
the proposed XSL formatting objects allow one to express this kind of
"flowed grid of size-balanced items"?
______________________________________
Joe Kesselman  / IBM Research
Unless stated otherwise, all opinions are solely those of the author.


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread