Subject: Re: [xsl] Function arguments (was regexps once) From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx> Date: Mon, 14 Jan 2002 15:24:20 +0000 |
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" /> with: <xsl:template name="my:foo"> <xsl:value-of select="." /> </xsl:template> and: <xsl:copy-of select="my:foo()" /> with: <xsl:function name="my:foo"> <xsl:result> <xsl:value-of select="." /> </xsl:result> </xsl:function> 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. Cheers, Jeni --- Jeni Tennison http://www.jenitennison.com/ XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] Function arguments (was r, Joerg Pietschmann | Thread | Re: [xsl] Function arguments (was r, G. Ken Holman |
RE: Regular expression functions (W, Chris Bayes | Date | [xsl] XSLT (XML Schema to XML Docum, Alex Genis |
Month |