Re: [xsl] functions and XSLT

Subject: Re: [xsl] functions and XSLT
From: "David Rosenborg" <david.rosenborg@xxxxxxxxxx>
Date: Tue, 13 Mar 2001 10:21:30 +0100
Hi Dave,

> Some people have expressed a strong preference for the ability to write
> functions in XSLT be available for XSLT 1.1.  I think this is unrealistic.
> XSLT 1.1 is intended to make incremental improvements to XSLT 1.0; XSLT 2.0
> is intended to include major new functionality.  It's important that such an
> issue be given much discussion before being recommended by W3C, because any
> modifications that were insufficiently thought through before publication as
> XSLT 1.1 would be extremely difficult to remove later.

I think the strong preferences are about being able to define extension functions
in XSLT in genereal, not for a specific version of XSLT. Until W3C decides on
such functionality, it can exist, and already exists, as extensions to XSLT 1.0.
Indeed the requiement for user defined functions appear in the requirements
document for XSLT 2.0 but I don't think this is because some anticipated
complexity compared to other improvements. I wouldn't say user defined extension
functions in XSLT would be a less incremental step than say xsl:script is.
I think it's more of a timing/priority issue.

> The concept of subroutine is expressed in XSLT by the template.  Templates
> take parameters; templates define scope; templates encapsulate algorithms;
> templates compute returned results.  So why is it that proposals to extend
> XSLT to allow the creation of functions written in XSLT go to the trouble
> of inventing a new syntax to define them?
>
> I've been asking myself "what is so different between a named template and
> this exsl:function?"  I haven't come up with a good answer, so now I'm
> asking you.  

XSLT templates can only create result tree fragments. An important aspect of
user defined functions is the ability to return arbitrary XPath values, including
node sets. That's the main reason why it's not sufficient to use named templates.

> Is there a difference in accessibility from XPath expressions?
> No, it would be just as easy to reference a named template from an XPath
> expression as it would be to reference an exsl:function, if the XPath
> spec allowed this sort of thing.  Is there a difference in accessibility
> of source-tree-fragment nodes?  No, the definition of "exsl:function"
> doesn't imply that nodes being returned are from the source tree.

The problem is that it cannot *return* nodes comfing from, for instance,
the source tree. It can only *create* new nodes. New nodes has their
own base URI for example. In XSLT 1.0 this is the URI of the stylesheet,
in XSLT 1.1 you can change this by xsl:base but it wouldn't solve the problem
in general.

Cheers,

</David>

David Rosenborg
Pantor Engineering AB



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


Current Thread