[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

Re: [xsl] template return value


Subject: Re: [xsl] template return value
From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx>
Date: Wed, 12 Dec 2001 18:13:30 +0000

Hi Charly,

> Is it possible to write functions in XSL. If not is there a way
> around . I need to call a template and store the output (or result)
> into a variable.

You can call the template from the body of the xsl:variable, as you've
been shown. The trouble with this method is that the variable gets
assigned a result tree fragment. Usually that doesn't matter (because
result tree fragments are automatically and mostly correctly converted
to strings or numbers when you use them in a context that requires a
string or number). However, you can't return a node set from a
template.

So if the result you want is a node set, you have two options.

Firstly, you can return a result tree fragment containing copies of
the nodes, then convert the result tree fragment to a node using an
extension node-set() function (e.g. exsl:node-set(), xalan:nodeSet(),
msxsl:node-set()). These functions return the root node of the result
tree fragment as a node set, so you usually need to step down to its
child to get the information you want.

Secondly, you can use an extension that allows you to define
extension functions yourself, and return node sets from these
extension functions. For example, you could use func:function (see
http://www.exslt.org/functions) in Saxon, 4XSLT, libxslt or jd.xslt,
msxsl:script in MSXML or xalan:component/xalan:script in Xalan.

Cheers,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/


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



Current Thread