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 2945 - [XSLT] validated content in a variable
Summary: [XSLT] validated content in a variable
Status: CLOSED FIXED
Alias: None
Product: XPath / XQuery / XSLT
Classification: Unclassified
Component: XSLT 2.0 (show other bugs)
Version: Candidate Recommendation
Hardware: PC Windows XP
: P2 normal
Target Milestone: ---
Assignee: Michael Kay
QA Contact: Mailing list for public feedback on specs from XSL and XML Query WGs
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-02-27 21:54 UTC by Joanne Tong
Modified: 2006-05-09 14:21 UTC (History)
0 users

See Also:


Attachments

Description Joanne Tong 2006-02-27 21:54:05 UTC
Consider this example:

<xsl:stylesheet version="2.0"
	xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
	xmlns:xs="http://www.w3.org/2001/XMLSchema"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

<xsl:template match="/">
	<xsl:variable name="x">
		<xsl:document validation="strict">
			...
			<a xsi:type="xs:integer">123</a>
			...
		</xsl:document>
	</xsl:variable>
	<xsl:value-of select="$x//a instance of xs:integer" />
</xsl:template>

</xsl:stylesheet>

The user probably expects the content of variable x to be validated and the 
xsl:value-of expression to return true.  However, this is not the case because 
an xsl:document is used implicitly to construct the temporary tree and default-
validation attribute is not specified in the xsl:stylesheet element.  Thus, 
all type information in variable x are stripped and the xsl:value-of 
expression returns false.  This would probably surprise most users since this 
is not obvious from reading the sections on xsl:variable and validation.  So I 
suggest adding an example or a note in the specification to explain the 
importance of specifying either the as attribute or the default-validation 
attribute to preserve type information.  The WG should also consider the 
alternative to always preserve type information in a variable by adding 
validation="preserve" to the implicit document node.
Comment 1 Michael Kay 2006-03-02 19:15:47 UTC
I believe this is covered by 19.2.2:

Validation is not applied to temporary trees unless the document node is
constructed using an xsl:document instruction. Similarly, validation is not
applied to document nodes created using xsl:message. (This is equivalent to
using validation="preserve": nodes within temporary trees retain their type
annotation.)

So I don't think that the problem you describe actually arises.

I have to say it took me some time to find this, and it might be appropriate to
mention it in section 9.4. - and perhaps to get rid of the brackets in the
quoted paragraph!

Michael Kay
(personal response)
Comment 2 Michael Kay 2006-04-27 20:01:52 UTC
Editorial changes have been made as follows:

(a) in the example in section 9.4 showing the equivalence to an explicit call of xsl:document, the xsl:document instruction now specifies validation="preserve".

(b) an explanatory paragraph has been added in 9.4 to reinforce the statement already present in 19.2.2:

No document-level validation takes place (which means, for example, that there is no checking that ID values are unique). However, type annotations on nodes within the new tree are copied unchanged.

(c) the parentheses have been removed from the cited text in 19.2.2
Comment 3 Sharon Adler 2006-05-09 14:21:47 UTC
SCA closed following 4 May Telcon where M. Kay text was accepted.