Re: [xsl] Kosher XSLT 3.0 numbering solution?

Subject: Re: [xsl] Kosher XSLT 3.0 numbering solution?
From: "Sewell, David R. (drs2n) dsewell@xxxxxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Thu, 1 Sep 2016 16:14:38 -0000
A two-pass solution was one of the things that occurred to me. But "cheating" with the global variable update makes the single pass easy enough that I didn't bother. Certainly for more complex situations it would be preferable.

David

On Thu, 1 Sep 2016, Graydon graydon@xxxxxxxxx wrote:

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



-- David Sewell Manager of Digital Initiatives The University of Virginia Press Email: dsewell@xxxxxxxxxxxx Tel: +1 434 924 9973 Web: http://www.upress.virginia.edu/rotunda

Current Thread