<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://www.w3.org/Bugs/Public/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.4"
          urlbase="https://www.w3.org/Bugs/Public/"
          
          maintainer="sysbot+bugzilla@w3.org"
>

    <bug>
          <bug_id>28888</bug_id>
          
          <creation_ts>2015-07-03 09:23:19 +0000</creation_ts>
          <short_desc>[xslt 3.0] xsl:on-empty with xsl:value-of</short_desc>
          <delta_ts>2015-08-17 08:37:33 +0000</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>XPath / XQuery / XSLT</product>
          <component>XSLT 3.0</component>
          <version>Last Call drafts</version>
          <rep_platform>PC</rep_platform>
          <op_sys>All</op_sys>
          <bug_status>CLOSED</bug_status>
          <resolution>FIXED</resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>P2</priority>
          <bug_severity>normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Michael Kay">mike</reporter>
          <assigned_to name="Michael Kay">mike</assigned_to>
          <cc>abel.braaksma</cc>
          
          <qa_contact name="Mailing list for public feedback on specs from XSL and XML Query WGs">public-qt-comments</qa_contact>

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>121588</commentid>
    <comment_count>0</comment_count>
    <who name="Michael Kay">mike</who>
    <bug_when>2015-07-03 09:23:19 +0000</bug_when>
    <thetext>Given the following:

&lt;a&gt;
  &lt;xsl:value-of select=&quot;@href&quot;/&gt;
  &lt;xsl:on-empty select=&quot;&apos;(no link)&apos;&quot;/&gt;
&lt;/a&gt;

users might find it surprising that if there is no @href attribute, the result will be the empty element &lt;a/&gt;. The reason is that in this situation the result of the xsl:value-of instruction is a text node whose string value is zero length; it is not an empty sequence. Therefore as far as xsl:on-empty is concerned, the result of the sequence constructor is non-empty.

Zero-length text nodes are ignored in the rules for constructing complex content (e.g. the content of the a element) but they are not ignored for the purposes of xsl:on-empty.

It&apos;s complicated by the fact that zero-length text nodes are not ignored everywhere, e.g in the body of xsl:variable or xsl:function:

&lt;xsl:variable name=&quot;x&quot; as=&quot;item()*&quot;&gt;
  &lt;xsl:value-of select=&quot;@href&quot;/&gt;
  &lt;xsl:on-empty select=&quot;&apos;(no link)&apos;&quot;/&gt;
&lt;/xsl:variable&gt;

Simply changing the rule so that xsl:on-empty ignores zero-length text nodes gives streamability problems with, for example,

&lt;xsl:variable name=&quot;x&quot; as=&quot;item()*&quot;&gt;
  &lt;xsl:on-empty select=&quot;&apos;(no link)&apos;&quot;/&gt;
  &lt;xsl:value-of select=&quot;@href&quot;/&gt;
  &lt;xsl:value-of select=&quot;@href&quot;/&gt;
  &lt;xsl:value-of select=&quot;a&quot;/&gt;
&lt;/xsl:variable&gt;

where the result of on-empty needs to be inserted into the result sequence before the three zero-length text nodes, but we can&apos;t evaluate it until the end.

There is a workaround, which is to write

&lt;a&gt;
  &lt;xsl:conditional-content&gt;
    &lt;xsl:value-of select=&quot;@href&quot;/&gt;
  &lt;/xsl:conditional-content&gt;
  &lt;xsl:on-empty select=&quot;&apos;(no link)&apos;&quot;/&gt;
&lt;/a&gt;

but it&apos;s not pretty.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>121589</commentid>
    <comment_count>1</comment_count>
    <who name="Michael Kay">mike</who>
    <bug_when>2015-07-03 10:01:29 +0000</bug_when>
    <thetext>Another workaround is:

&lt;a&gt;
  &lt;xsl:sequence select=&quot;data(@href)&quot;/&gt;
  &lt;xsl:on-empty select=&quot;&apos;(no link)&apos;&quot;/&gt;
&lt;/a&gt;

Perhaps we just need to give all users a brain transplant...</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>121921</commentid>
    <comment_count>2</comment_count>
    <who name="Michael Kay">mike</who>
    <bug_when>2015-07-09 17:31:01 +0000</bug_when>
    <thetext>In discussion today, there was some sentiment to changing the rule for xsl:on-empty so that it ignores zero-length text nodes, but at the same time changing the rules so that xsl:on-empty must come at the end of the sequence constructor.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>121936</commentid>
    <comment_count>3</comment_count>
    <who name="Michael Kay">mike</who>
    <bug_when>2015-07-09 23:49:01 +0000</bug_when>
    <thetext>I propose the following changes:

(a) if an xsl:on-empty instruction appears in a sequence constructor then (i) it must be the only xsl:on-empty instruction in the sequence constructor, and (ii) it must not be followed by any other instructions, with the exception of xsl:fallback. (It may however be followed by non-instructions such as xsl:catch if the context permits).

(b) an xsl:on-empty instruction is evaluated if and only if there is no preceding instruction in the sequence constructor whose evaluation produces a substantive result. For this purpose a result is substantive if it is not any of the following:

b(i) an empty sequence
b(ii) a text node whose string value is zero length
b(iii) a document node having no children

[Note: the significance of these choices is that these values have no effect in the common case where the sequence constructor is used for constructing the content of nodes: see *Constructing complex content* and *Constructing simple content*.]

(c) xsl:on-non-empty can continue to appear anywhere, and repeatedly. The rules change to:

an xsl:on-non-empty instruction is evaluated if and only if there is an instruction in the sequence constructor, other than an xsl:on-empty or xsl:on-non-empty instruction, whose evaluation produces a substantive result [defined as above].</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>122278</commentid>
    <comment_count>4</comment_count>
    <who name="Michael Kay">mike</who>
    <bug_when>2015-07-23 17:25:02 +0000</bug_when>
    <thetext>The proposal was accepted.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>122631</commentid>
    <comment_count>5</comment_count>
    <who name="Michael Kay">mike</who>
    <bug_when>2015-08-17 08:37:33 +0000</bug_when>
    <thetext>The change has been applied to the spec.

I included one minor correction: the result of an instruction is treated as empty not only if it IS a zero-length text node or childless document node, but also if it CONSISTS ENTIRELY of such nodes.</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>