Re: [xsl] Converting milestone tags

Subject: Re: [xsl] Converting milestone tags
From: Wendell Piez <wapiez@xxxxxxxxxxxxxxxx>
Date: Thu, 14 Oct 2010 10:35:22 -0400
Hi Josef,

Also, see my demo at, where I do this on a small scale, but with a general approach that handles arbitrary overlap. Consider the links in the right column in particular, where the flattened markup is induced back into hierarchies. The names of the elements you want stacked in the hierarchy are passed in at runtime. The method does not depend on any particular structural arrangement of milestones, as long as they are paired. (If you have milestones whose start or ends are implied, these are expanded in a first step, not shown in the demo, which starts with a normalized format.) Nor does it use any "tag-writing" hacks, which can be expedient but which also introduce dependencies on organization in the source.

The demo is slightly documented at (it served as a demonstration behind a paper I gave in London in July).

The stylesheets are in a pipeline, currently implemented in Cocoon. (What is posted on line is a static copy.) Some stylesheets (but not all) require XSLT 2.0. But it's not beginner stuff.

Mail me off list if you want to know more.


At 03:45 AM 10/14/2010, Mike wrote:
This class of problems is quite tricky. The most general approach is to flatten the first hierarchy, so everything is reduced to milestones, and then use positional grouping to construct the new hierarchy from the flat structure.

If you have access to a good library, try looking for Michael Jackson's 1970s books on Jackson Structured Programming, where he tackles this class of problem under the heading of "boundary conflict". The vocabulary is different - it's all about sequential processing of hierarchic files on magnetic tape - but the logic is the same, and it's the most systematic treatment I've seen. Essentially he shows that if the hierarchic structure of the input and output are in some sense congruent, then a single tree walk over the input can handle the problem, but if they aren't then you can devise a new intermediate hierarchy - perhaps very flat - that is congruent with both the input and the output, so one tree walk will get you from the input to the intermediate tree, and a second tree walk will get you from the intermediate tree to the output. (This is assuming of course that you don't have an ordering conflict, which is true in your case).

Your example doesn't need the full generality of this approach, because the start/end milestones are always siblings and are always matched in the same paragraph, but your discussion indicates that you might want to tackle things that go beyond this example.

Michael Kay

Wendell Piez                            mailto:wapiez@xxxxxxxxxxxxxxxx
Mulberry Technologies, Inc.      
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

Current Thread