Subject: Re: [xsl] Kosher XSLT 3.0 numbering solution? From: "Martin Honnen martin.honnen@xxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> Date: Thu, 1 Sep 2016 14:04:10 -0000 |
I have a numbering task that is trivially easy to handle using an XSLT extension that permits modification of global variables (such as saxon:assign) but which is harder to accomplish via pure XSLT. I don't *need* to accomplish this as I have code that works fine, but I'm just curious about alternate solutions.
I have an XML file representing the contents of a printed book. I need to add page break indicators that carry the page numeration, e.g. <pb n="51"/>. Because I'm lazy, I just want to plug in empty markers and then run a script to add the numeration.
This would be a straightforward job for xsl:number if all pagination was sequential. However, parts of the book are commented out, so there may be a page jump from say page 11 to page 30. In a case like that, I will insert <pb n="30"/> to provide a hard-coded indication of the number. That makes use of xsl:number more complicated. The solution via updates to a global variable is simple, along the lines of
<xsl:variable name="bodyPageNo" select="0" as="xs:integer" saxon:assignable="yes"/> <xsl:template match="pb"> <xsl:variable name="pageNumber"> <saxon:assign name="bodyPageNo" select=" if (@n) then xs:integer(@n) else $bodyPageNo + 1 "/> <xsl:value-of select="$bodyPageNo"/> </xsl:variable> [etc.]
If I avoid saxon:assign, I don't see any way around some moderately messy brute-force calculation in the <pb> template to identify the closest preceding <pb> element with an @n value (if any), and use that value plus the number of intervening <pb> elements to assign a numeration to the current element. Does anything jump out as a more elegant approach?
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] Kosher XSLT 3.0 numbering sol, David Sewell dsewell | Thread | Re: [xsl] Kosher XSLT 3.0 numbering, Sewell, David R. (dr |
[xsl] Kosher XSLT 3.0 numbering sol, David Sewell dsewell | Date | Re: [xsl] Kosher XSLT 3.0 numbering, Sewell, David R. (dr |
Month |