This is an archived snapshot of W3C's public bugzilla bug tracker, decommissioned in April 2019. Please see the home page for more details.

Bug 5126 - Assertions: usability
Summary: Assertions: usability
Status: RESOLVED WORKSFORME
Alias: None
Product: XML Schema
Classification: Unclassified
Component: Structures: XSD Part 1 (show other bugs)
Version: 1.1 only
Hardware: PC Windows XP
: P2 normal
Target Milestone: ---
Assignee: C. M. Sperberg-McQueen
QA Contact: XML Schema comments list
URL:
Whiteboard: important, hard, XPath cluster
Keywords:
Depends on:
Blocks:
 
Reported: 2007-10-02 17:07 UTC by Michael Kay
Modified: 2008-01-23 20:24 UTC (History)
0 users

See Also:


Attachments

Description Michael Kay 2007-10-02 17:07:02 UTC
I've been doing some experiments with assertions.

It seems to be quite common to define an assertion that constrains some element deep within the document to be consistent with an attribute of the document element (for example, a version attribute). For example one might constrain an XSLT stylesheet to say:

<xs:assert test="if (@version='1.0') then empty(.//xsl:result-document) else true()"/>

The problem about such assertions is that they have to appear on the complexType of the document element (because they apply to the subtree rooted at that node). This makes it almost impossible when the assertion fails to provide diagnostics  saying where in the instance document the problem actually arises.

I'm not proposing that we change the rule that the assertion belongs with the type that defines the subtree within which the constraint applies. But I think there might be a case for allowing the condition to be specified in two parts:

<xs:assert select=".//xsl:result-document" test="empty(ancestor-or-self::xsl:*[@version='1.0'])"/>

(which in this example is actually a more precise expression of the desired constraint, since the version attribute can appear anywhere)

The default for select would be select="." which leaves test with the current meaning. In the presence of the select attribute, the test would be applied to each node selected by the select expression, allowing the diagnostics to refer to the position of that selected node. Furthermore, this allows multiple errors to be reported if more than one selected element is invalid.

I know that some might think this introduces unnecessary complexity. But in its absence, users are going to have to do some complex queries to find out where the errors in their documents actually are.
Comment 1 Michael Kay 2007-12-27 00:59:59 UTC
An observation: if we decide not to change the spec in the way suggested, then it might be possible as a workaround for an implementation to recognize assertions of the form "every $x in a/b/c satisfies COND" and in such cases, report the location of every $x that doesn't satisfy the constraint. This would solve the problem in effect by means of a tacit conspiracy between implementors and users to provide favourable treatment for certain kinds of XPath expression.
Comment 2 David Ezell 2008-01-23 20:24:28 UTC
The WG decided to classify this issue as WORKSFORME.  Rationale is that while the original suggestion might fix this particular problem, other equally important problems may arise later requiring other kinds of decompositions of the XPath.  The WG finds the solution in comment #1 very useful, and instructs the editors to make a point of including a note explaining this idiom.

Please let us know if you agree with this resolution of your issue, by adding a comment to the issue record and changing the Status of the issue to Closed. Or, if you do not agree with this resolution, please add a comment explaining why. If you wish to appeal the WG's decision to the Director, then also change the Status of the record to Reopened. If you wish to record your dissent, but do not wish to appeal the decision to the Director, then change the Status of the record to Closed. If we do not hear from you in the next two weeks, we will assume you agree with the WG decision.