Re: dl/dt/dd matching

Subject: Re: dl/dt/dd matching
From: James Clark <jjc@xxxxxxxxxx>
Date: Tue, 12 Jan 1999 10:31:34 +0700
Francois Belanger wrote:
> I'm scratching my head on this one.

I've been scratching my head for years on this one.  It's a problem in
DSSSL too.

> What were trying to do is layout a suite of dt/dd within a dl as a table
> with a row for each dt. Since there's no container for each dt (the
> corresponding dl are siblings, not children of the dt node), how can one
> start a new row for each dt and express that in XSL?

XSL can't handle this at the moment, but I think it needs to.

The processing model for xsl:for-each and xsl:apply-templates is:

1. Use a select pattern to create a list of nodes.

2. Instantiate a template once for each member of the list, creating a
document fragment for each node.

3. Append the document fragments created by step 2.

The last WD modified by this slightly by adding an optional step 1a that
sorts the list.

One way to solve the problem is to refine step 3.

Suppose step 1 gives a list of element nodes:

[A1, B1, A2, B2, A3, B3]

Step 2, gives us a list of document fragments:

[r(A1), r(B1), r(A2), r(B2), r(A3), r(B3)]

where r(E) is the document fragment that results from processing element

Step 3 gives us:

r(A1) + r(B1) + r(A2) + r(B2) + r(A3) + r(B3)

where + indicates concatenation.

One solution is to allow nodes to be grouped together:

[[A1, B1], [A2, B2], [A3, B3]]

and then specify an operation f on the results of groups, thus getting

f(r(A1) + r(B1)) + f(r(A2) + r(B2)) + f(r(A3) + r(B3))

For example, it might look like this:

<xsl:template match="dl">
    <xsl:for-each select="dt|dd">
      <xsl:group start="dt">

xsl:group modifies the operation of xsl:for-each and xsl:apply-templates
just as xsl:sort does.  The start attribute is a match pattern that
specifies the nodes that start a group; the content specifies what to do
with the result of processing the members of the group; within
xsl:group, xsl:contents refers to the result of appending the results of
processing the members of the group.

Another approach:

<xsl:template match="dl">

<xsl:template match="dt">

<xsl:template match="dd">

xsl:continue says the content gets added to the previous sibling in the
result element tree.   This is simpler but has some problems.


 XSL-List info and archive:

Current Thread