[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

user-defined XSLT functions and stylesheet variables?

Subject: user-defined XSLT functions and stylesheet variables?
From: "David Birnbaum djbpitt@xxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Fri, 18 Jun 2021 17:41:31 -0000
 user-defined XSLT functions and stylesheet variables?
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

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.