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

Subject: Re: [xsl] Providing a value for the 'select' attribute
From: Michael Kay <mike@xxxxxxxxxxxx>
Date: Mon, 03 Oct 2011 23:45:54 +0100
On 03/10/2011 22:26, G. Ken Holman wrote:
At 2011-10-03 14:19 -0700, Mark wrote:
I have been using the following idiom when providing a value for C"b,EselectC"b,B 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>

The above is a text node, as is this:


<xsl:param name="file-type">.htm</xsl:param>
Actually, no. Both are document nodes (known in 1.0 as root nodes) having a single text node as a child.

This is slightly different in that it is a string:


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

But for your use that difference is nuanced based only on how the item is stored in memory.

If the system isn't able to do some quite sophisticated optimizations, it's very likely that a tree containing a document node and a text node will be much more expensive than a simple string. They are equivalent in most situations, but not all, which means the optimizer can't always replace one with the other. The main difference is the effective boolean value: <xsl:if test="$file-type"> works differently for strings and nodes.

Why write three lines of inefficient code where one line of efficient code will do the job?

(Saxon will do the optimization, incidentally, if every reference to $file-type appears in a context where the value of the variable is atomized.)

Michael Kay
Saxonica

Current Thread