Project

Profile

Help

Is there a difference regarding the visibility of named templates in explicit and implicit packages?

Added by Martin Honnen over 4 years ago

When I use the transform function with initial-template and a stylesheet-location pointing to an XSLT 2 or 3 stylesheet module with a xsl:stylesheet root element I find that Saxon allows me to call templates in that module if they have no explicit visibility specified.

However, when the stylesheet-location points to an explicit package with a xsl:package root element having such templates, I get an error XTDE0040 that the template is private.

Tested with Saxon 9.9.1.4 HE Java.

I have tried to find any section in the XSLT 3 spec that somehow defines a different visibility for a named template without a visibility attribute depending on whether the template is inside of a xsl:stylesheet or a xsl:package but I haven't found anything.

Have I overlooked something in the spec?


Replies (4)

Please register to reply

RE: Is there a difference regarding the visibility of named templates in explicit and implicit packages? - Added by Michael Kay over 4 years ago

Yes, there is a difference. For backwrds compatibility, named templates are public in an implicit package, but private in an explicit package.

RE: Is there a difference regarding the visibility of named templates in explicit and implicit packages? - Added by Martin Honnen over 4 years ago

But for named functions, this difference is not been made?

Is that difference for named templates defined in the XSLT 3 spec or just part of the Saxon design?

RE: Is there a difference regarding the visibility of named templates in explicit and implicit packages? - Added by Michael Kay over 4 years ago

Named functions are private by default in both cases. There was no backwards-compatibiity reason to make functions public by default, because XSLT 2.0 did not have the capability to call functions externally.

RE: Is there a difference regarding the visibility of named templates in explicit and implicit packages? - Added by Michael Kay over 4 years ago

Note that if you're looking for where this is specified, it's in §3.5, where it describes the transformation used to produce an explicit package from an implicit package. Note in particular:

    <t:expose component="mode" names="*" visibility="public"/>
    <t:expose component="template" names="*" visibility="public"/>

which causes modes and templates to be exposed as public.

    (1-4/4)

    Please register to reply