Re: [xsl] mode

Subject: Re: [xsl] mode
From: "Imsieke, Gerrit, le-tex" <gerrit.imsieke@xxxxxxxxx>
Date: Thu, 14 Apr 2011 22:13:55 +0200
On 2011-04-14 21:47, G. Ken Holman wrote:
At 2011-04-14 20:40 +0100, Andrew Welch wrote:
> Remember that mode names can be namespace qualified. When I create XSLT
> stylesheet libraries, I use two namespaces for the name of the modes
engaged
> therein: a public one that my library users are allowed to use (to
exploit
> the library), and a private one that my library users are expressly
told not
> to use (so as not to inadvertently interfere with the operation of the
> library).

That's an interesting workaround to the lack of visibility modifiers
for the xslt library designer...

I use the same two-namespace convention for all globally-declared variables in the library. And keys. And named templates. *Everything* with a globally-scoped name in the library is namespace qualified. I don't bother with locally-scoped variables.

Without namespaces, if my imported library makes use of a global
variable named "x", and my user's importing stylesheet inadvertently
declares its own variable named "x", then my library won't work as
expected.

Namespaces in libraries avoid execution errors and duplicate declaration
errors.

Very useful. And this approach has been available since day one of XSLT
1.0 and so has been a long-time practice for me. I first started using
it when contracted to create a library being sent out of the development
team to many remote departments who were going to have their own
developers write importing stylesheets.

That's a real "pro tip" (as @ndw would put it), Ken! Haven't thought about using namespaced modes. I sometimes provided library functions (namespace-qualified, as demanded by the spec) which applied internal templates *in unqualified modes*.
And I was always afraid that people would accidentally use the same unqualified mode name for their own templates, thus overwriting my rules.
It's good to distinguish between API namespace (the one that the publicly available function, or named template, or variable, or key, is in) and internal namespace.
This is actually a good use case for justifying the much-contested XML namespaces.


Gerrit

Current Thread