[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: Mon, 14 Jan 2002 15:24:20 +0000
templates as function arguments
Hi Joerg,

>> the only exising built-in function that returns a node tree -
>> document() -
> What about current()?

The current() function returns an existing node from the document
you're looking at - similar, in a way, to id() and key(). The
document() function, on the other hand, returns a whole new tree with
its own document node.

You would never imagine that current() == current() could be false,
since they both return a reference to the same node. On the other
hand, you could imagine that:

  document('foo.xml') == document('foo.xml')

would be false, if each call to the document() function constructed a
new document from whatever file you point to.

> IMHO user defined functions should not depent implicitely of the
> context where they are called, they not be allowed to invoke
> current(), nor position() and last() outside of places where XPath
> provides a context. Necessary context information can always be
> passed explicitely (no need to go through the discussion of the
> "dynamic binding" thread again...)

Certainly they could be designed like that. In some ways I think it
would be a shame, though - I like having the shorthand that name()
means name(.) but maybe that's just me. It also undermines the
equality between:

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


<xsl:template name="my:foo">
  <xsl:value-of select="." />


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


<xsl:function name="my:foo">
    <xsl:value-of select="." />

I'm not actually sure whether that's a good thing or a bad thing, but
I suspect that there being such a fundamental (yet hidden) difference
between named templates and functions will be more confusing than
getting the rules right about when functions return a new node tree
and when they don't.

The other thing is that every set of XSLT instructions requires a
focus - a context item, position, size and so on. What you're really
saying is that this focus should not be the same as the focus at the
point at which the function is called. I think there are two
possibilities about what that focus *could* be, in that case:

 - use the same focus as is used for other top-level elements (e.g.
   global variables) and make the context item the document node of
   the principal source document (with position 1, size 1)

 - use the context document at the point of the function call as the
   context item (with position 1, size 1)

I think that of the two, the latter will probably lead to something
that works in a way closer to what people expect, especially given
that we're going to be working with more "source documents" now that
there are no RTFs.


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.