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

Re: Function arguments (was regexps once)

Subject: Re: Function arguments (was regexps once)
From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx>
Date: Tue, 15 Jan 2002 13:57:58 +0000
definition of function argument
Joerg Pietschmann wrote:
> Jeni Tennison <jeni@xxxxxxxxxxxxxxxx> wrote:
>> > IMHO user defined functions should not depent implicitely of the
>> > context where they are called...
>> It also undermines the equality between: [ calling named templates
>>   and  <xsl:copy-of select="my:foo()" /> ]
> That's a valid point. I didn't remember that named templates inherit
> the context from where they were called, probably because i've been
> bitten a few times by this feature and i now prefer to pass
> everything through parameters, even ".".

Yes - personally I think that using the context node in named
templates is bad practice. I usually use modes instead, so I guess the
fairer comparison would be with:

  <xsl:apply-templates select="." mode="my:foo" />


<xsl:template match="node()|@*" mode="my:foo">
  <xsl:value-of select="." />

[I think I'm being completely irrational in viewing this kind of moded
template as any better than a named template - it's not as if the
match attribute of the template actually gives you any idea about what
the node you're processing is. I guess that in real situations, the
match pattern can be less general, and it gives you a bit of
extensibility as you can add other templates in the same mode to
process specific kinds of nodes.]

Hmm... makes me think of a version of xsl:function with a match
attribute - that could indicate both that the context item should be
implicitly passed as an argument, and its required type [something
that you can't currently do without passing it explicitly].

But then, why make a distinction between xsl:function and xsl:template
at all? If the proposals that I made about sequence constructors were
accepted, then you could define both functions and templates with the
same xsl:template declaration, and just call them in different ways in
different situations. In other words, if you had:

<xsl:template name="my:foo">

You could call it with either:

  <xsl:call-template name="my:foo" />


  <xsl:copy-of select="my:foo()" />

Not all templates could be adapted to functions of course - only those
that had a name (or a mode, perhaps) with a namespace.

I wonder, actually, whether the introduction of functions will
effectively do away with named templates. Given that functions and
named templates are basically equivalent (a function is more flexible
currently, in fact), why would anyone want to go through typing all
those xsl:with-params when they could just define a function instead,
use the much-reduced syntax and have the result accessible within
XPath expressions?



Jeni Tennison

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

Current Thread


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.
First Name
Last Name
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.