Re: Empty elements

Subject: Re: Empty elements
From: Nick Browne <NickBrowne@xxxxxxxxxxxxxxx>
Date: Thu, 21 Sep 2000 13:13:01 +0100
Dave, I added another node to your test : <node id="id04"><x> </x></node>
i.e. a non-empty descendent of a node without text children.

Results were : Instant Saxon 5.3.2 -->  Node: id04 is not empty using
string(.)
                                                            Node: id04 has
children

                      Oracle 2.0.2.9        -->   Node: id04 is  empty
using string(.)
                                                             Node: id04 has
children

Just to make sure that Saxon was correct, I went back to basics, breaking
it down :

 <xsl:when test="not(   string(  .  )  )">

(a)     .  =  Current node -->  argument to string() is a node set with 1
node.
(b)   Result of string() with a node set is string-value of first node in
set.
(c)   String-value of node = concatenation of all descendant text nodes -->
a single space.
(d)  Implicit conversion of non-empty string to boolean --> True
(e)  not( True) --> False

Therefore this 'when' test fails and the inverse test will pass, 15-0 to
Saxon.

Digging a bit deeper the problem seems to be Oracle stripping out the text
node child of the <x> element. Replacing the single blank with a non-blank
(non-whitespace ?) character gives the expected result. I assume it is not
differentiating between whitespace nodes between closing and opening tags
of different elements and whitespace nodes within an element. Setting the
Oracle parser to preserve whitespace nodes gives the same result as Saxon
but of course introduces all the extra whitespace nodes. (I am assuming
that Instant Saxon, by default, strips pure whitespace text nodes between
elements).

This then brings us round to the meaning of stripping of pure white space
text nodes - so its back to the spec(s) and FAQs then !

Regards

Nick Browne
Slipstone Ltd

"Pawson, David" wrote:

> Playing with Mike Kays definition of empty elements,
> http://sources.redhat.com/ml/xsl-list/2000-09/msg00598.html
>
> <doc>
> <node id="@id00"/>
> <node id="id1"> </node>
> <node id="id02"><!--comment--></node>
> <node id="id03"><x/></node>
>  </doc>
>
> <xsl:template match="node">
>   <xsl:call-template name="mt"/>
> </xsl:template>
>
> <xsl:template name="mt">
>   <xsl:choose>
>   <xsl:when test="not(string(.))">
>     Node: <xsl:value-of select="@id"/> is  empty using string(.)&nl;
>   </xsl:when>
>   <xsl:when test="string(.)">
>     Node: <xsl:value-of select="@id"/> is not empty using string(.)&nl;
>   </xsl:when>
> <xsl:otherwise>
>   Otherwise 1 reached on  <xsl:value-of select="@id"/> .&nl;
> </xsl:otherwise>
> </xsl:choose>
> <xsl:choose>
>   <xsl:when test="not(node())">
>     Node: <xsl:value-of select="@id"/> has no children &nl;
>   </xsl:when>
>   <xsl:when test="node()">
>     Node: <xsl:value-of select="@id"/> has children &nl;
>   </xsl:when>
> <xsl:otherwise>
>   Otherwise 2 reached on  <xsl:value-of select="@id"/> .&nl;
> </xsl:otherwise>
> </xsl:choose>
> </xsl:template>
>
> gives
>   Node: @id00 is  empty using string(.)
>      Node: @id00 has no children
>
>     Node: id1 is not empty using string(.)
>      Node: id1 has children
>
>     Node: id02 is  empty using string(.)
>      Node: id02 has children
>
>     Node: id03 is  empty using string(.)
>      Node: id03 has children
>
> Interesting, and quite informative.
> (I'll be using this one :-)
>
> Regards DaveP
>
>  XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list

--
Nick Browne
Technical Director
Slipstone Ltd

This e-mail is intended for the above-mentioned recipient only and it may
contain confidential or privileged information. If you have
received it in error please accept our apologies. Please notify us
immediately and delete the e-mail. You may not copy, distribute,
disclose or take any action based on the content of this message or it's
attachments.

Whilst efforts have been taken to check  for the presence of computer
viruses you are advised that you open any attachments at your
own risk.



 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread