<?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>29237</bug_id>
          
          <creation_ts>2015-10-24 13:44:01 +0000</creation_ts>
          <short_desc>[xslt 3.0] Bug in CSV package example</short_desc>
          <delta_ts>2015-11-05 18:43:45 +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>123887</commentid>
    <comment_count>0</comment_count>
    <who name="Michael Kay">mike</who>
    <bug_when>2015-10-24 13:44:01 +0000</bug_when>
    <thetext>In the example CSV package in 3.5.7.8, we have a variable declaration

&lt;xsl:variable name=&quot;csv:csv-quote-ok&quot; visibility=&quot;private&quot;&gt;
   &lt;xsl:sequence select=&quot;
       if (string-length($csv:quote) ne 1) 
       then error(xs:QName(&apos;csv:ERR001&apos;), 
                  &apos;Incorrect length for $csv:quote, should be 1&apos;) 
       else ()&quot; /&gt;
&lt;/xsl:variable&gt;

and we say: 

When the value of csv:quote is suitable, the variable csv:csv-quote-ok will evaluate to the empty sequence

But this is incorrect. Because the variable declaration has no &quot;as&quot; attribute, the value is not an empty sequence but a childless document node.

I am fixing this by changing the variable declaration to:

&lt;xsl:variable name=&quot;csv:csv-quote-ok&quot; visibility=&quot;private&quot; 
              as=&quot;xs:error?&quot; select=&quot;
       if (string-length($csv:quote) ne 1) 
       then error(xs:QName(&apos;csv:ERR001&apos;), 
                  &apos;Incorrect length for $csv:quote, should be 1&apos;) 
       else ()&quot; /&gt;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>123889</commentid>
    <comment_count>1</comment_count>
    <who name="Michael Kay">mike</who>
    <bug_when>2015-10-24 13:59:21 +0000</bug_when>
    <thetext>To be honest, I&apos;m still slightly uneasy about this mechanism. XPath &quot;errors and optimisation&quot; says that if an expression has only one possible value, other than an error, the system doesn&apos;t need to evaluate it merely in order to test for the error. So an optimizing processor doesn&apos;t need to evaluate csv-quote-ok.

And in any case, the mechanism is clearly a hack.

A clean solution would be to declare a type:

&lt;xsl:import-schema&gt;
  &lt;xs:schema targetNamespace=&quot;http://example.com/csv&quot;&gt;
    &lt;xs:simpleType name=&quot;one-char&quot;&gt;
      &lt;xs:restriction base=&quot;xs:string&quot;&gt;
        &lt;xs:length value=&quot;1&quot;/&gt;
      &lt;/
    &lt;/
  &lt;/
&lt;/

and then declare the variable to have this type:

&lt;xsl:variable name=&quot;csv:quote&quot; as=&quot;csv:one-char&quot; select=&quot;csv:one-char(&apos;&amp;quot;&apos;)&quot; visibility=&quot;public&quot;/&gt;

Any overriding variable is required to have the same type.

Although I know there are practical problems because schema-awareness is not offered by all processors, this seems a much worthier solution to include in a spec where we are supposed to be demonstrating good practice. The way to constrain the type of a variable is by using the &quot;as&quot; attribute.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>123892</commentid>
    <comment_count>2</comment_count>
    <who name="Michael Kay">mike</who>
    <bug_when>2015-10-24 14:21:15 +0000</bug_when>
    <thetext>Unfortunately the solution proposed in comment #1 opens up further questions. If a using stylesheet wishes to override the variable csv:quote, then it needs to declare its type as csv:one-char. But this type name is not in scope unless the using package imports the schema for the csv namespace: and how do you import a schema that is defined inline in another package?

To solve this, I suggest adding the following rule to xsl:import-schema:

When package P uses package Q, the schema components imported by package Q do not automatically become available in package P. However, if package P contains an xsl:import-schema declaration with namespace=N, then any schema components in namespace N that are imported by package Q also become available in package P. There is no need in this case to specify a schema-location attribute, and any such attribute is ignored. This includes the case where the xsl:import-schema declaration in package Q defines an inline schema, that is, where it has an xs:schema element as a child.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>124024</commentid>
    <comment_count>3</comment_count>
    <who name="Michael Kay">mike</who>
    <bug_when>2015-11-01 15:33:30 +0000</bug_when>
    <thetext>I have adopted the solution of using a second (private) variable $csv:validated-quote which is set to the value of $csv:quote provided it is valid. This seems easier to explain and involves less hackery. It is still subject to the objection that when an expression is either a known value or an error, the error checking can be bypassed, but it&apos;s probably pretty safe in practice.

Since this is an example and therefore editorial, I am marking it as resolved.</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>