xsl-list
[Top] [All Lists]

Re: [xsl] Kosher XSLT 3.0 numbering solution?

2016-09-01 11:14:51
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(_at_)marost(_dot_)ca wrote:

On Thu, Sep 01, 2016 at 03:48:45PM -0000, Michael Kay 
mike(_at_)saxonica(_dot_)com
scripsit:
On 1 Sep 2016, at 16:27, Liam R. E. Quin liam(_at_)w3(_dot_)org
<xsl-list-service(_at_)lists(_dot_)mulberrytech(_dot_)com> 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(_at_)virginia(_dot_)edu   Tel: +1 434 924 9973
Web: http://www.upress.virginia.edu/rotunda
--~----------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
EasyUnsubscribe: http://lists.mulberrytech.com/unsub/xsl-list/1167547
or by email: xsl-list-unsub(_at_)lists(_dot_)mulberrytech(_dot_)com
--~--

<Prev in Thread] Current Thread [Next in Thread>