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

Subject: Re: [xsl] user-defined XSLT functions and stylesheet variables?
From: "Dimitre Novatchev dnovatchev@xxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Sat, 19 Jun 2021 01:26:20 -0000
>  Is there agreement about Best Practice with respect to using stylesheet
(global) variables inside user-defined functions?

Not if one wants to have reusable functions -- many of them, in useful
libraries that you can use again and again and that you can share with
everyone.

Best of all, define your functions as pure XPath inline functions, then the
whole notion of something called "XSLT" is non-existent...

These can be used either in pure XPath expressions, or in anything that
uses or extends XPath, like XQuery or XSLT or ... you name it.

Cheers,
Dimitre

On Fri, Jun 18, 2021 at 10:41 AM David Birnbaum djbpitt@xxxxxxxxx <
xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> wrote:

> Dear XSLT-list,
>
> Is there agreement about Best Practice with respect to using stylesheet
> (global) variables inside user-defined functions?
>
> If I want to be able to reuse my function in different contexts, passing
> in everything the function needs as an explicit parameter ensures that it
> won't have expectations about the global context. There may also be
> philosophical reasons that functions should be entirely self-contained, and
> should not depend on variables available in the execution context.
>
> Meanwhile, since XSLT does not allow variables to be modified, the concern
> (in other languages) about modifying global variables inside functions does
> not obtain in XSLT, and my use of stylesheet variables would be read-only.
> If I've written a one-off function intended for use only in a single
> stylesheet, passing global variables into it as explicit parameters is more
> verbose than relying on the fact that the function, like everything else in
> the stylesheet, has access to stylesheet variables. Passing everything in
> explicitly does make the function more self-documenting (since everything
> the function uses is declared as a parameter inside the body) and perhaps
> also more convenient to test, but what do other developers think about how
> to balance those advantages against the added verbosity?
>
> Best,
>
> David
> XSL-List info and archive <http://www.mulberrytech.com/xsl/xsl-list>
> EasyUnsubscribe <http://lists.mulberrytech.com/unsub/xsl-list/782854> (by
> email <>)
>


-- 
Cheers,
Dimitre Novatchev
---------------------------------------
Truly great madness cannot be achieved without significant intelligence.
---------------------------------------
To invent, you need a good imagination and a pile of junk
-------------------------------------
Never fight an inanimate object
-------------------------------------
To avoid situations in which you might make mistakes may be the
biggest mistake of all
------------------------------------
Quality means doing it right when no one is looking.
-------------------------------------
You've achieved success in your field when you don't know whether what
you're doing is work or play
-------------------------------------
To achieve the impossible dream, try going to sleep.
-------------------------------------
Facts do not cease to exist because they are ignored.
-------------------------------------
Typing monkeys will write all Shakespeare's works in 200yrs.Will they write
all patents, too? :)
-------------------------------------
Sanity is madness put to good use.
-------------------------------------
I finally figured out the only reason to be alive is to enjoy it.

Current Thread