xsl-list
[Top] [All Lists]

Re: [xsl] Kosher XSLT 3.0 numbering solution?

2016-09-01 11:28:08

If I understand the requirement correctly, I'm sure I had an XSLT 2 version of 
this in use some years ago, following advice from someone on this list.  Though 
I can't now find the files.

Algorithm is something like:
  count( number of nodes since most recent one with an explicit page number )
  + most recent explicit page number.

I was expecting it to be quite fiddly but it wasn't much more than a one-liner.


Regards,
Richard.




Richard Kerry
BNCS Engineer, SI SOL Telco & Media Vertical Practice
T: +44 (0)20 3618 2669
M: +44 (0)7812 325518
4 Triton Square, Regent’s Place, London NW1 3HG
richard(_dot_)kerry(_at_)atos(_dot_)net

________________________________________
From: Sewell, David R. (drs2n) dsewell(_at_)virginia(_dot_)edu 
[xsl-list-service(_at_)lists(_dot_)mulberrytech(_dot_)com]
Sent: 01 September 2016 17:15
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: Re: [xsl] Kosher XSLT 3.0 numbering solution?

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

Atos, Atos Consulting, Worldline and Canopy The Open Cloud Company are trading 
names used by the Atos group. The following trading entities are registered in 
England and Wales: Atos IT Services UK Limited (registered number 01245534), 
Atos Consulting Limited (registered number 04312380), Atos Worldline UK Limited 
(registered number 08514184) and Canopy The Open Cloud Company Limited 
(registration number 08011902). The registered office for each is at 4 Triton 
Square, Regent’s Place, London, NW1 3HG.The VAT No. for each is: GB232327983.

This e-mail and the documents attached are confidential and intended solely for 
the addressee, and may contain confidential or privileged information. If you 
receive this e-mail in error, you are not authorised to copy, disclose, use or 
retain it. Please notify the sender immediately and delete this email from your 
systems. As emails may be intercepted, amended or lost, they are not secure. 
Atos therefore can accept no liability for any errors or their content. 
Although Atos endeavours to maintain a virus-free network, we do not warrant 
that this transmission is virus-free and can accept no liability for any 
damages resulting from any virus transmitted. The risks are deemed to be 
accepted by everyone who communicates with Atos by email.
--~----------------------------------------------------------------
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>