Re: [xsl] is it possible to simulate <xsl:import> precedence within a single stylesheet file?

Subject: Re: [xsl] is it possible to simulate <xsl:import> precedence within a single stylesheet file?
From: "Michael Kay mike@xxxxxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Tue, 25 Apr 2023 13:55:40 -0000
The general answer is no, because xsl:apply-importts is very specific about
searching only the import tree below a specified stylesheet module, and that
can't be replilcated within a single module, even with a conversion to
xsl:next-match.

In the SaxonJS XSLT compiler we do have a mechanism that reduces import
precedence to a single totally ordered property which can be assigned to each
module as soon as it is processed. We label modules with two properties:

      <!-- $moduleLabel is a string that identifies the hierarchic position of
a module in the include/import hierarchy.
             Conceptually, if module A imports B and C, then the labels are A,
AZ, and AY respectively. "Z" here represents
             the last letter in some suitably large alphabet; the suffix for
an included or imported module is allocated in
             document order, counting downwards from this terminator. Module
labels are used only as an intermediate value used
             for computing precedence labels; the module label is the same
regardless whether modules are imported or
             included -->

        <!-- $precLabel is a string that reflects the import precedence of a
module. If a module is included, then
             the precedence label is the same as the precedence label of its
parent in the include/import tree; if
             it is imported, then it is the same as the module label. For
example, if A imports B and C and includes D,
             and D imports E, then the precedence labels of A, B, C, D, and E
are Z, ZZ, ZY, Z, and ZXZ respectively.
             When the precedence labels are arranged in alphabetical order
this gives a ranking of A=D=1, E=2, C=3, B=4,
             which correctly reflects the XSLT rules for calculating import
precedence. Note that "Z" here denotes
             the last letter in a suitably large alphabet, so we don't
actually impose a limit of 26 imports. -->

Combining this alphabetic precedence label with a numeric priority label to
give a single numeric rank is straightforward just by running through the
values in sorted order.

So it's really only apply-imports that makes the exercise impossible.

Michael Kay
Saxonica


> On 25 Apr 2023, at 13:48, Chris Papademetrious
christopher.papademetrious@xxxxxxxxxxxx
<xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> wrote:
>
> Hello XSLT friends,
>
> Martinbs XSLT fiddle site <https://xsltfiddle.liberty-development.net/>
has become one of my favorite XSLT learning and development tools. The ability
to see stylesheet results in real-time is enormously helpful in developing a
mental model both of the problem being solved and of XSLT itself.
>
> Today I need to develop some functionality for a DITA-OT processing
stylesheet. The top-level stylesheet is a bunch of <xsl:import> imports of
lower-level files:
>
> <?xml version="1.0" encoding="UTF-8"?>
> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform
<http://www.w3.org/1999/XSL/Transform>" version="2.0">
>   <xsl:import
href="plugin:org.dita.base:xsl/preprocess/topicpullImpl.xsl"/>
>   <xsl:import
href="plugin:org.dita.base:xsl/preprocess/topicpull-task.xsl"/>
>   <xsl:import
href="plugin:org.dita.base:xsl/preprocess/topicpull-pr-d.xsl"/>
>   <xsl:import
href="plugin:com.oxygenxml.pdf.css:xsl/preprocess/topicpull.xsl"/>
>   <xsl:import href="plugin:com.synopsys.processing:topicpull.xsl"/>
>   <xsl:import href="plugin:com.synopsys.mini-toc:topicpull-minitoc.xsl"/>
>   <xsl:import href="plugin:com.synopsys.preserve.keyrefs:topicpull.xsl"/>
> </xsl:stylesheet>
>
> It would be super cool to create an XSLT stylesheet that flattens a
top-level DITA-OT stylesheet into something that can XSLT-fiddled with.
>
> However, I am not sure how the import precedence rules described in 3.11.3
Stylesheet Import <https://www.w3.org/TR/xslt-30/#import> could be replicated
when flattening the stylesheet. The only solution I can think of is to convert
all implicit match priority values to explicit priority values (match
parsing!!), then completely linearize the whole mess to implement precedence
using ranges of priority values. And even if I wanted to do this (I donbt!),
I am no longer fiddling with the original code because now everything uses
arbitrary priority values.
>
> Is there some way to simulate import precedence (not priority) within a
single stylesheet file?
>
> Thanks as always!
>
> -----
> Chris Papademetrious
> Tech Writer, Implementation Group
> (610) 628-9718 home office
> (570) 460-6078 cell
>
> XSL-List info and archive <http://www.mulberrytech.com/xsl/xsl-list>
> EasyUnsubscribe <http://lists.mulberrytech.com/unsub/xsl-list/293509> (by
email <>)

Current Thread