xsl-list
[Top] [All Lists]

RE: Let's face it: side effects are sometimes necessary!

2002-12-03 04:01:04

I used to use <xsl:variable ...> elements on the toplevel of 
an XSLT transform for their side-effects. The 
xsl:variable/@select would call into some extension function, 
that would set up some static data (initializations) of some gizmo.

At the top level of the stylesheet, surely it's much easier to declare
xsl:param's and supply the initial value from the calling application?

I am thinking of:

<xsl:variable name="gizmo" saxon:eval-immediately="yes"
    xmlns:g="java:my.package.Gizmo"
    select="g:new($gizmoInitializationParameter)"/>

If you specify saxon:assignable="yes", the variable will be evaluated
whether or not it is referenced (except in the case of global variables
that are overridden by another of higher precedence).

One reasonably reliable way to force any XSLT processor to evaluate your
extension functions is to make the function return an empty string, and
call the function in an <xsl:value-of/>. The system can't possibly know
that it will return an empty string, so it has to call the function; and
moreover, it's very unlikely that it will call it out-of-sequence,
because it has to put the results together in the right order.  

Michael Kay
Software AG
home: Michael(_dot_)H(_dot_)Kay(_at_)ntlworld(_dot_)com
work: Michael(_dot_)Kay(_at_)softwareag(_dot_)com 


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list