Re: [xsl] Kosher XSLT 3.0 numbering solution?

Subject: Re: [xsl] Kosher XSLT 3.0 numbering solution?
From: "Graydon graydon@xxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Thu, 1 Sep 2016 16:02:59 -0000
On Thu, Sep 01, 2016 at 03:48:45PM -0000, Michael Kay mike@xxxxxxxxxxxx
scripsit:
> > On 1 Sep 2016, at 16:27, Liam R. E. Quin liam@xxxxxx
> > <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> wrote: But surely it's not
> > that hard to write a recursive template or function that finds the
> > previous page break and adds one to it where needed?
> 
> Actually it's quite tricky if you want to have a function/template
> that both returns a modified version of the source tree with new
> numbers inserted, and also returns the latest number used. Returning
> two results using maps is possible, but not easy.
> 
> Computing the numbers is ideally done by a fold operation that
> processes all the nodes in the tree in document order, and XSLT 3.0
> accumulators are essentially syntactic sugar for such a fold
> operation.

With XSLT 2.0, every time I had to worry about this sort of thing --
table spans, numbering legislation, complex figure numbers -- I found it
was much better to do an initial pass or passes to calculate values and
to attach those values to the elements of an instance of the source
document as attributes.  A subsequent pass did the manipulation on the
modified source document instance using the pre-calculated values.

XSLT 2.0 and subsequent makes very this easy; you can stick each pass in
a variable, and apply-templates selecting that variable for the next
pass.

It might not meet your sense of elegance, but I've found it a good way
to keep the complexities distinct.

-- Graydon

Current Thread