Re: empty string as empty node-set: why not?

Mike Brown wrote:

> Per section 11.2 of the XSLT draft, "If the variable-binding element has
> empty content and does not have a select attribute, then the value of the
> variable is an empty string."
> 
> So, if I were to do this:
> 
>         <xsl:call-template name="do_something">
>                 <!-- not passing a parameter "foo" -->
>         </xsl:call-template>
> 
>         <xsl:template name="do_something">
>             <xsl:param name="foo"/>
>             <!-- I wish $foo were a node-set -->
>             <xsl:if test="$foo/SomeChildren">I see SomeChildren</xsl:if>
>         </xsl:template>
> 
> ...I would be committing a crime because $foo is a string at this point (an
> empty string), not a node-set, and nothing can be converted to a node-set,
> per section 3.3 of the XPath draft.
> 
> I can work around this a couple of ways:
> 
> 1. A default value for the parameter can be fudged to be an empty
> node-set...
> 
>         <xsl:param name="foo" select="/nonexistent/path"/>
> 
> This is ugly and /nonexistent/path could conceivably return a non-empty
> node-set, unless one imposes a restriction on source trees to never contain
> nodes that would match that pattern.

This was discussed at an XSL WG meeting, and it was pointed out that

  select="/.."

is a simple way to get a node-set that is guaranteed to be empty.  We
felt this was enough for XSLT v1.

James

Received on Wednesday, 15 September 1999 12:32:20 UTC