Re: Best practice regarding empty node-set initialization

I like "/..".  We did consider adding a function to return an empty
node-set, but it didn't really see to buy anything over "../".

"G. Ken Holman" wrote:
> 
> Hi folks!
> 
> In XSLT/XPath 1.0 I've come across a situation where I need to default a
> parameter to an empty node-set so the parameter can subsequently be used in
> a union expression but be validly a node-set the first time around.
> 
> Below is an illustration of how a defaulted empty node-set expression would
> be useful ... I've distilled this from my work from today.
> 
> You can see I'm using the expression "/@empty-node-set" which is guaranteed
> (for XML 1.0) to be empty because the root node can never have attribute nodes.
> 
> Is it true there is no standardized XPath expression for an empty node-set,
> and if so, could this be added in the future, please?
> 
> Thanks!
> 
> ................. Ken
> 
> T:\ftemp>type test.xsl
> <?xml version="1.0"?>
> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
>                  version="1.0">
> 
> <xsl:template match="/">                         <!--root rule-->
>    <xsl:message>Test 1</xsl:message>
>    <xsl:call-template name="test1">
>      <xsl:with-param name="nodes" select="."/>
>    </xsl:call-template>
>    <xsl:message>Test 2</xsl:message>
>    <xsl:call-template name="test2"/>
> </xsl:template>
> 
> <xsl:template name="test1">
>    <xsl:param name="nodes" select="/@empty-node-set"/>
>    <xsl:variable name="test" select="$nodes | ."/>
> </xsl:template>
> 
> <xsl:template name="test1">
>    <xsl:param name="nodes"/>
>    <xsl:variable name="test" select="$nodes | ."/>
> </xsl:template>
> 
> </xsl:stylesheet>
> 
> T:\ftemp>xt test.xsl test.xsl
> file:/T:/ftemp/test.xsl:1: Test 1
> file:/T:/ftemp/test.xsl:1: Test 2
> cannot convert to node-set
> 
> T:\ftemp>saxon test.xsl test.xsl
> Test 1
> Test 2
> Error while applying stylesheet
> At xsl:variable on line 21 of file:/T:/ftemp/test.xsl: Cannot convert value
> [""]
>   to a node-set
> 
> T:\ftemp>
> 
> --
> G. Ken Holman                    mailto:gkholman@CraneSoftwrights.com
> Crane Softwrights Ltd.             http://www.CraneSoftwrights.com/m/
> Box 266, Kars, Ontario CANADA K0A-2E0   +1(613)489-0999   (Fax:-0995)
> Web site: XSL/XML/DSSSL/SGML services, training, libraries, products.
> Book: Practical Transformation Using XSLT and XPath ISBN1-894049-05-5
> Article:          What is XSLT? http://www.xml.com/pub/2000/08/holman
> Next public instructor-led training:     2000-09-19/20,2000-10-03/05,
> -                  2000-10-09/10,2000-10-19,2000-11-06/07,2000-11-12,
> -                                            2000-12-03/04,2001-01-27

Received on Monday, 18 September 2000 04:17:34 UTC