xsl-list
[Top] [All Lists]

[xsl] Re: Re: error in xsl:key

2008-09-19 15:19:53
Please take a look at this xslt (input is not important):

<xsl:stylesheet version="2.0"
 xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
 xmlns:xs="http://www.w3.org/2001/XMLSchema";
 exclude-result-prefixes="xs">

 <xsl:key name="key" match="*" use="
   if (ancestor-or-self::b) then
     error()
   else
     1"/>

 <xsl:template match="/">
   <xsl:variable name="doc">
     <a>
       <b/>
       <c/>
     </a>
   </xsl:variable>

   <xsl:message select="key('key', 1, $doc/a/c)"/>
 </xsl:template>

</xsl:stylesheet>

According to your description "it doesn't define which
order the conditions are applied in" the preceding stylesheet
may rightfully fail. However, in the more extreme case, when
$doc does not contain element b, but some other document available
(or will be available) do contains element b, egnine is allowed to
fail also.

This looks bizarre.
--
Vladimir Nesterovsky
http://www.nesterovsky-bros.com/


One can argue other way: key() function should never return a
node for which evaluation of use resulted in an error.

Firstly, key() is defined to return "every node $N that satisfies the
following conditions:". It doesn't define which order the conditions are
applied in; for example it doesn't say whether you evaluate the use
expression for every node in the universe, and then look at the subset of
these that are in the subtree rooted at $top (the third argument), or
whether you first look in the subtree and then evaluate the use condition.
Saxon searches the document containing $top for all nodes that match the
match pattern, evaluates the use expression for all of these, and then sees
which of these are in the subtree rooted at $top. But other strategies are
allowed.

Concerning errors, section 2.9 says:

Because different implementations may optimize execution of the stylesheet
in different ways, the detection of dynamic errors is to some degree
implementation-dependent. In cases where an implementation is able to
produce the final result trees without evaluating a particular construct,
the implementation is never required to evaluate that construct solely in
order to determine whether doing so causes a dynamic error.

There are a few situations in which errors are recoverable (for example, an
error in evaluating the match pattern of a template - but NOT the match
pattern of a key). These are clearly described as such in the spec. All
other dynamic errors are non-recoverable.




--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

<Prev in Thread] Current Thread [Next in Thread>