Re: [xsl] Mode in XSLT 3.0

Subject: Re: [xsl] Mode in XSLT 3.0
From: "Toshihiko Makita tmakita@xxxxxxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Thu, 27 Jul 2017 02:32:09 -0000
> I think you're starting from the position that if the XML vocabulary that you're dealing with is partitioned into modules, then it ought to be possible to mirror the independent > modules in the XML vocabulary with independent packages in the stylesheet. I would suggest that if these packages are to be truly independent, then they have to use
> different modes for their template rules.


From the stylesheet implementer's perspective, I am confused about this suggestion. Why? This is because we cannot have a way to make highly independent stylesheet packages for XML documents. As mentioned in the past post, modern XML document standard such as DITA, S1000D, DocBook has the recursive content models. This prevents making independent stylesheet modules. We always distinguish paragraph templates and table templates in another module in XSLT 2.0. But sometimes paragraph element can contain tables and table cells can contain the paragraph elements. In this case we use <xsl:apply-templates/> in the table cell template as:

"I don't know about the detailed content models of table cell. But it will be defined and implemented in another stylesheet modules. So I pass the controls by xsl:apply-templates instruction to the xsl:template in another module in the assumption that the relevant template will handle the table cell contents properly."

This is the implicit rule in XSLT 2.0 stylesheet.

However we cannot do the same thing using xsl:package in XSLT 3.0 because the public default mode cannot be shared between xsl:packages.
I have been hoping for XSLT 3.0 xsl: package for a long time because it offers many attractive functions. But currently I afraid that xsl:package mechanism has no opportunity to apply for the XML documents processing stylesheets field. If my concern is based on extraordinary speculation, please indicate it concretely to me.


--
/*--------------------------------------------------
 Toshihiko Makita
 Development Group. Antenna House, Inc. Ina Branch
 Web site:
 http://www.antenna.co.jp/
 http://www.antennahouse.com/
 --------------------------------------------------*/

On 2017/07/26 8:01, Michael Kay wrote:
It's not clear to me what you are trying to achieve by using packages. The design intent of packages is that a package can be developed without any knowledge of, or dependency on, packages other than those it explicitly uses. If template rules for the same mode are distributed across two packages, neither of which uses the other, then the behaviour of one package would be affected by the presence of a package of which it has no knowledge. That goes directly against the design objectives for packages.

I think you're starting from the position that if the XML vocabulary that you're dealing with is partitioned into modules, then it ought to be possible to mirror the independent modules in the XML vocabulary with independent packages in the stylesheet. I would suggest that if these packages are to be truly independent, then they have to use different modes for their template rules.

Michael Kay
Saxonica

On 25 Jul 2017, at 16:45, Graydon graydon@xxxxxxxxx <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> wrote:

So I went and pulled the package example out of the spec and got that to
run from the command line.

I can construct (and have attached) a trivial example where there
are block, table, list, and figure elements and equally trivial packages
with block, table, list, and figure modes and template matches.

This is meant to be the simplest possible case that models DITA domains
(or HL7v3 component schemas, or any other lego-block style vocabulary.)

I can write a top-level stylesheet referencing all this and SaxonHE
9.8.0.3 will run it using

java -cp ~/bin/saxon/saxon9he.jar net.sf.saxon.Transform -it
-xsl:mode-eg.xsl -s:simple-eg.xml -o:test-out.xml
-lib:block-pkg.xsl:fig-pkg.xsl:table-pkg.xsl:list-pkg.xsl

If I'm understanding packages correctly, individual packages MUST have
their own unique modes.  Any given xsl:apply-templates instruction can
specify one and only one mode.  So in XSLT 3.0, if I want to have
several packages, one per domain/category/vocabulary-lego-block, and
apply them all in an apply-templates way to the source document, I must:

<xsl:template name="xsl:initial-template">
   <xsl:variable name="mode1">
       <xsl:apply-templates mode="main" />
   </xsl:variable>
   <xsl:variable name="mode2">
       <xsl:apply-templates select="$mode1" mode="block"/>
   </xsl:variable>
   <xsl:variable name="mode3">
       <xsl:apply-templates select="$mode2" mode="figure"/>
   </xsl:variable>
   <xsl:variable name="mode4">
       <xsl:apply-templates select="$mode3" mode="table"/>
   </xsl:variable>
   <xsl:variable name="mode5">
       <xsl:apply-templates select="$mode4" mode="list"/>
   </xsl:variable>
   <xsl:sequence select="$mode5"/>
</xsl:template>

This -- provided all the packaged modes have @on-no-match="shallow-copy"
-- gets the expected result, but I look at it and think that I have to
be doing this wrong.

Is there a better way to approach this?

Thanks!
Graydon
<xslt-package-modes.zip>

-- /*-------------------------------------------------- Toshihiko Makita Development Group. Antenna House, Inc. Ina Branch E-Mail tmakita@xxxxxxxxxxxxx 8077-1 Horikita Minamiminowa Vil. Kamiina Co. Nagano Pref. 399-4511 Japan Tel +81-265-76-9300 Fax +81-265-78-1668 Web site: http://www.antenna.co.jp/ http://www.antennahouse.com/ --------------------------------------------------*/

Current Thread