W3C home > Mailing lists > Public > xsl-editors@w3.org > July to September 2000

Best practice regarding empty node-set initialization

From: G. Ken Holman <gkholman@cranesoftwrights.com>
Date: Fri, 15 Sep 2000 14:21:28 -0400
Message-Id: <4.2.0.58.20000915140912.01f48580@pop1.attglobal.net>
To: xsl-editors@w3.org
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 Friday, 15 September 2000 14:22:07 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Monday, 7 December 2009 10:59:50 GMT