Re: [xsl] Providing a value for the 'select' attribute

Subject: Re: [xsl] Providing a value for the 'select' attribute
From: Wendell Piez <wapiez@xxxxxxxxxxxxxxxx>
Date: Mon, 03 Oct 2011 17:30:35 -0400
Mark,

On 10/3/2011 5:19 PM, Mark wrote:
Hi,
I have been using the following idiom when providing a value for
bselectb in statements like <xsl:param>, <xsl:variable>, etc., when the
value provided is not an xsl object. Is this correct or is some other
form preferred?

<xsl:param name="file-type">
  <xsl:text>.htm</xsl:text>
</xsl:param>

This is not incorrect. So it is correct. Some, however (including some readers of this list), would argue that it is not optimal.


In essence, absent a specification otherwise (using xsl:param/@as), you are declaring the paramater to be a temporary tree (or, in XSLT 1.0, a result tree fragment), in this case a root with a single text node child.

If your intention is that $file-type be a string, you should say:

<xsl:param name="file-type" select="'.htm'"/>

or

<xsl:param name="file-type" as="xs:string">.htm</xsl:param>

(which is essentially the same as what you have with as="xs:string" added, since the effect of the xsl:text is cosmetic).

Advantages to binding to a string instead of a temporary tree include that it will be faster when it is processed as a string (since it won't have to be cast to one); and that it will probably behave more as you expect it to when under stress ... for example, a string value of "" is cast to Boolean false(), while a temporary tree with a single text node will cast to Boolean true(), even if that text node has no string value.

Cheers,
Wendell

======================================================================
Wendell Piez                            mailto:wapiez@xxxxxxxxxxxxxxxx
Mulberry Technologies, Inc.                http://www.mulberrytech.com
17 West Jefferson Street                    Direct Phone: 301/315-9635
Suite 207                                          Phone: 301/315-9631
Rockville, MD  20850                                 Fax: 301/315-8285
----------------------------------------------------------------------
  Mulberry Technologies: A Consultancy Specializing in SGML and XML
======================================================================

Current Thread