Re: [xsl] xslt style

Subject: Re: [xsl] xslt style
From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx>
Date: Fri, 10 Jan 2003 16:39:00 +0000
Hi Mike,

>> Well, here is an example of what I think is a bad design:
>> 
>> <xsl:template match="person">
>>   <xsl:call-template name="getName" />
>> </xsl:template>
>> 
>> <xsl:template name="getName">
>>   <xsl:value-of select="givenName" />
>>   <xsl:text> </xsl:text>
>>   <xsl:value-of select="familyName" />
>> </xsl:template>
>> 
>> The getName template uses the context node at the point the 
>> template was called in order to resolve the two paths 
>> ("firstName" and "surname").
>
> Then you'll be pleased to hear that xsl:function in XSLT 2.0 won't
> allow you to access the context node at the point the function was
> called - you have to supply it as an explicit argument.

Well no, not particularly. You're confusing my opinion that it's best
practice to have context that's used in a template or function
declared explicitly in that template or function with a desire to
force people to pass values explicitly when calling that template or
function.

I have no problem with using:

  <xsl:call-template name="getName" />

to call a template with no parameters. I think it's best practice for
the template to be defined as:

<xsl:template name="getName">
  <xsl:param name="person" select="." as="element person" />
  <xsl:value-of select="givenName" />
  <xsl:text> </xsl:text>
  <xsl:value-of select="familyName" />
</xsl:template>

with the fact that the context node is used within the template made
explicit, but that doesn't mean that I want to write that as a
constraint in the language.

Similarly, I would have no problem with people defaulting arguments,
in function calls; I just think that it would be best practice for
functions that use context information to declare parameters for that
context information explicitly.

But anyway, I understand that there are other reasons that
user-defined functions in XSLT 2.0 can't use context information (not
that I can remember what they are right now...).

Cheers,

Jeni

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


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


Current Thread