Duncan,
As you hopefully saw from Mukul's post, this problem is not
impossible in XSLT. Not only that but it's well enough known to have
a name, as he said, "positional grouping" (because nodes are grouped
based on their positions relative to one another).
Following onto that, I have just a couple of comments:
1. Whitespace-only text nodes can be a problem that requires a bit of
sensitivity to handle properly. Options include:
* remove them using a preprocess of some kind (such as an XSLT stylesheet)
* in the stylesheet, use xsl:strip-space to remove them from the
source tree before the stylesheet does its thing
* write extra code or more complex XPath expressions that take account of them
2. In general, the kind of transformation you are attempting is
called an "up-conversion" since it adds information that is not
already explicit in the markup. Here, for example, you want your
output to reflect a structure that is not explicit in the input --
you know a list starts because you have a series of br elements, but
there is no element already "containing" the list. (If there were,
the transform from one format to another would be trivial.)
Actually, this is *not* what XSLT 1.0 was designed for
("down-conversions"), though it is not uncommon these days to use it for this.
Accordingly, one option for you to consider is to use XSLT 2.0, which
has features designed to support just this kind of work. In XSLT 1.0
it sometimes feels like mowing your lawn with a pair of scissors. Not
impossible. Just hard enough to make you wonder where you left your sanity.
3. If you want to stick with 1.0 (or even if not) you may find that
it's much easier both to conceptualize and to execute the conversion
in several phases. "Pipelines" (the term of art for several
conversions performed serially) turn out to be really useful for
up-conversions in general. This is partly because up-conversion
frequently requires cleaning the cruft out of the data to simplify
the problem before the actual conversion, and this is usefully
relegated to an earlier pass.
Ask again if you're still stuck.
Cheers,
Wendell
At 10:42 PM 6/4/2006, you wrote:
I am playing around with transforming something like this:
<br />
<br />
<b>word:</b> definition<br />
<b>word:</b> definition<br />
<br />
<br />
into something like this:
<dl>
<dt>word:</dt><dd>definition</dd>
<dt>word:</dt><dd>definition</dd>
</dl>
...
--~------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--