RE: [xsl] Grouping into a table (for vertical alignment)
Subject: RE: [xsl] Grouping into a table (for vertical alignment)|
From: Wendell Piez <wapiez@xxxxxxxxxxxxxxxx>
Date: Fri, 28 May 2004 11:49:26 -0400
At 11:01 PM 5/27/2004, you wrote:
Thanks Wendell... trying to figure it out now :p
>Jeni works through one of these in entry 12 in the FAQ
>page at http://www.dpawson.co.uk/xsl/sect2/N4486.html#d4726e727.
Looking at it too, entry 12 actually allows me to handle my problem without
a <xsl:key> ...
That's right: it's the other technique I mentioned: the "forward walk" or
"tree visitor". The key-based technique is just called "key-based
positional grouping" (since the nodes are grouped based on their relative
positions), although I like to call it "levitation".
The trade-off is that walking the tree explicitly makes for more complex
templates that work in what, to a newbie, is a highly unorthodox way, since
they use <xsl:apply-templates select="following-sibling::*"
mode="walk"/> or the like. Using keys is a bit more elegant in the XSLT,
arguably, but lays the stress on that key declaration, whose XPath (as you
saw) can be ... "ornate", let's say.
I got a question on entry 17:
> <xsl:apply-templates mode="inGroup"
> select="following-sibling::*[position() < $vGroupLength]"/>
"vGroupLength" is the number of elements in the group.
How does the "position()" work when used in the above manner,
is it just the "context position" within (1) the node list of only
or (2) a node list of all siblings? I guess the first, but I just want to
You are correct, it's the node list of the following siblings. (The context
of a predicate is provided by the nodes and node-set the predicate operates
But you don't actually want this as it groups by a count -- first three
nodes, next three nodes, next three nodes -- or they could be in twelves or
nineteens: you get the idea. Whereas you need to group based on what nodes'
neighbors are (which is why your problem is a bit harder).
I really appreciate all the help I am getting from this list. Thanks all.
Sure. You have a toughie, but it's been done. Digging in the archives for
"forward walk" or "tree visitor" would be a way to learn more about the
technique I did *not* explain (but which some say is easier: I dunno, if
you understand keys I think they're about the same).
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