Re: [xsl] user-defined XSLT functions and stylesheet variables?

Subject: Re: [xsl] user-defined XSLT functions and stylesheet variables?
From: "Graydon graydon@xxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Sun, 20 Jun 2021 00:35:06 -0000
On Sun, Jun 20, 2021 at 12:11:50AM -0000, Christophe Marchand cmarchand@xxxxxxxxxx scripsit:
> All the responses given by Eliot and Liam respect Clean Code[1] best
> practises. Many principles must be respected if you expect your code may
> evolve :

I think this is one of those places where the imperative best practise
and the declarative best practise aren't perfectly congruent.

If you've got a global variable that provides part of the transform
context -- the big map of what the known languages use for quotation
marks, commas, and colons, say -- I think it's quite entirely harmless
to reference that from inside a function.  The testing should be looking
at the list of names in the map and making sure the expected names are
defined for each language, but presence of a transform context with
global constants -- how many of whatever to the EMU, how many points to
the inch, etc. -- is conceptually like amending the static context by
importing module functions.  I don't think it's harmful to use global
variables in this way.

(It does make me hope XSLT 4 allows

<xsl:variable name="bigLookup" as="map(*)">
  <xsl:map>
  ....
  </xsl:map>
</xsl:variable>

to be declared static.)

-- 
Graydon Saunders  | graydonish@xxxxxxxxx
^fs oferiode, pisses swa mfg.
-- Deor  ("That passed, so may this.")

Current Thread