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 30222 - [xslt30] xsl:copy-of and base-uri
Summary: [xslt30] xsl:copy-of and base-uri
Status: NEW
Alias: None
Product: XPath / XQuery / XSLT
Classification: Unclassified
Component: XSLT 3.0 (show other bugs)
Version: Recommendation
Hardware: PC All
: 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: 2018-02-08 15:33 UTC by Michael Kay
Modified: 2019-02-19 21:20 UTC (History)
1 user (show)

See Also:


Attachments

Description Michael Kay 2018-02-08 15:33:15 UTC
In both the XSLT 2.0 and 3.0 specifications, we say for xsl:copy-of:


<quote>
The base URI of a node is copied, except in the case of an element node having an xml:base attribute, in which case the base URI of the new node is taken as the value of the xml:base attribute, resolved if it is relative against the base URI of the xsl:copy-of instruction. If the copied node is subsequently attached as a child to a new element or document node, the final copy of the node inherits its base URI from its parent node, unless this is overridden using an xml:base attribute.
</quote>

I've been struggling to understand exactly what this means, and I think the only interpretation that makes sense is that "a node" at the start of this paragraph refers to a node in the sequence returned by evaluating the select attribute; it does not refer to descendants of such nodes which are also copied as part of the subtree. 

So what happens to nodes deeper in the subtree? XQuery is explicit:

<quote>
When an element or processing instruction node is copied, its base-uri property is set to be the same as that of its new parent, with the following exception: if a copied element node has an xml:base attribute, its base-uri property is set to the value of that attribute, resolved (if it is relative) against the base-uri property of the new parent node.
</quote>

(It's clear from the context that this applies to nodes at any depth in the subtree: the intro says: "a new copy is made of the given node and all nodes that have the given node as an ancestor, collectively referred to as copied nodes. The properties of the copied nodes are as follows:")

We don't have such a rule for XSLT. In particular, we don't make it clear what happens the copied subtree has elements with diverse base URIs because they were created by parsing different external entities. Does this diversity persist in the copied subtree? XQuery is explicit that the diversity is lost during a deep copy operation.

If we accept my interpretation of the phrase "the base URI of a node is copied", then we don't say what happens deeper down the tree.

If we go for an alternative reading, where "a node" refers to nodes at any depth, then the diversity is retained, but with nonsense happening if there are xml:base attributes present, and further nonsense happening when the entire copied subtree is attached to a new parent.

I think it would be useful to clarify the quoted paragraph as:

<quote>
For any node N that is explicitly selected by the evaluation of the select expression, the base URI of the new copy is as follows:

(a) if N is an element node having an xml:base attribute, the base URI of the new node is taken as the value of the xml:base attribute, resolved if it is relative against the base URI of the xsl:copy-of instruction

(b) otherwise the base URI of the new node is the same as the base URI of N.

For any element or processing-instruction node that has N as an ancestor, the base-uri property of the new copy is set to be the same as that of its new parent, with the following exception: if a copied element node has an xml:base attribute, its base-uri property is set to the value of that attribute, resolved (if it is relative) against the base-uri property of the new parent node.

Note: if two elements in a subtree have different base URIs for some reason unconnected with xml:base attributes, for example because they derive from different XML entities supplied as input to an XML parser, then these differences are lost when the subtree is copied.

Note: as a consequence of rules specified elsewhere (see Constructing Complex Content), if a node in the result of the xsl:copy-of instruction is subsequently attached as a child to a new element or document node, the final copy of the node inherits its base URI from its new parent node, unless this is overridden using an xml:base attribute.
</quote>

With this change, the XSLT rules become clear, and they are also equivalent to the XQuery rules (however, XQuery does not have the ability to create a parentless copy of a subtree, it can only copy a subtree in the course of attaching it to a new parent.)
Comment 1 Abel Braaksma 2019-02-19 21:20:59 UTC
A proposed erratum E16 has been published on 13 Feb 2019, HTML version: https://htmlpreview.github.io/?https://github.com/w3c/qtspecs/blob/master/errata/xslt-30/html/xslt-30-errata.html#E16

(I have not reviewed this in detail)