Subject: Re: [xsl] Function arguments (was regexps once) From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx> Date: Tue, 15 Jan 2002 13:57:58 +0000 |
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" /> with: <xsl:template match="node()|@*" mode="my:foo"> <xsl:value-of select="." /> </xsl:template> [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"> ... </xsl:template> You could call it with either: <xsl:call-template name="my:foo" /> or: <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? 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, Michael Kay |
Re: [xsl] Function arguments (was r, Joerg Pietschmann | Date | [xsl] xslt extensions - whats it ab, peter gibbons |
Month |