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 8219 - [XSLT] Shallow copy and xml:base
Summary: [XSLT] Shallow copy and xml:base
Status: CLOSED FIXED
Alias: None
Product: XPath / XQuery / XSLT
Classification: Unclassified
Component: XSLT 2.0 (show other bugs)
Version: Recommendation
Hardware: PC Windows NT
: P2 normal
Target Milestone: ---
Assignee: Michael Kay
QA Contact: Mailing list for public feedback on specs from XSL and XML Query WGs
URL: http://www.w3.org/TR/xslt20/#shallow-...
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-11-06 17:33 UTC by Tim Mills
Modified: 2010-07-20 16:04 UTC (History)
1 user (show)

See Also:


Attachments

Description Tim Mills 2009-11-06 17:33:20 UTC
The following paragraph towards the end of the Shallow copy section

"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  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."

is ambiguous in that it is unclear whether

"the case of an element node having an xml:base attribute"

refers to:

(1) an xml:base attribute of the element being copied, OR
(2) an xml:base attribute in the content sequence contained in the xsl:copy.


Consider the source document:

<?xml version="1.0"?>
<doc xml:base="http://source.base.uri">
  <inner xml:base="AAA/" />
</doc>

and the transformation:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                version="2.0">

  <xsl:template match="/doc/inner">
     <xsl:variable name="target" as="element()">
       <xsl:copy xml:base="http://copy.base.uri">
         <xsl:attribute name="xml:base">BBB/</xsl:attribute>
       </xsl:copy>
     </xsl:variable>
     <out>
       <xsl:value-of select="base-uri($target)" />
     </out>
  </xsl:template>

</xsl:stylesheet>

Interpretation (1):

The xml:base attribute is "AAA/"
Resolving against the base URI of xsl:copy gives "http://copy.base.uri/AAA/".
The result is therefore:

<out>http://copy.base.uri/AAA/</out>


Interpretation (2)

The xml:base attribute is "BBB/"
Resolving against the base URI of xsl:copy gives "http://copy.base.uri/BBB/".

The result is therefore:

<out>http://copy.base.uri/BBB/</out>


I suspect that interpretation 2 is correct, however, when I've tried this with an XSLT 2.0 implementation, the result was:

<out>http://source.base.uriAAA/BBB</out>
Comment 1 Michael Kay 2009-11-06 17:44:30 UTC
Sorry, but I don't see how any reasonable reader could arrive at interpretation 2. It seems to me perfectly clear that interpretation 1 is correct.

I guess we could change "The base URI of a node is copied ..." to "When a node is copied, its base URI is copied, ...". Would that be clearer?
Comment 2 Oliver Hallam 2009-11-06 20:00:45 UTC
Let me summarize the effects of the two interpretations:

Interpretation 1:
  a) If the source node has a relative xml:base attribute then the base URI is computed with this uri resolved against the uri of the xsl:copy instruction.  The xml:base attribute itself is not copied.

  b) Otherwise the base URI of the source node is used.

  c) xml:base attributes that appear in the copied node are ignored for purposes of computing the node's base URI.


Interpretation 2:
  a) If the copied node has an xml:base attribute then this is resolved against the base URI of the xsl:copy instruction. 

  b) Otherwise the base URI of the source node is used.


Surely the intention of this sentence was interpretation 2 and it was just poorly worded?

If the intention was indeed interpretation 1, then what was the justification for adding this condition?
Comment 3 Michael Kay 2009-11-06 22:13:15 UTC
OK, I see the problem now. The current text is taken from the identical text for the xsl:copy-of instruction, and it's written in the mistaken belief that when you copy an element, you copy its attributes. So it's written to say that the base-uri attribute of the element before copying should be used, but this doesn't make sense, because the intent of the rule is that the base URI of an element should always be consistent with its xml:base attribute if it has one, and in this case the xml:base attribute of the new node is not the same as the xml:base attribute of the old one.

So we should probably change the sentence

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  instruction.

to read

When a node is copied, its base URI is copied, except when the result of the xsl:copy instruction is an element node having an xml:base attribute, in which case the base URI of the new node is taken as the value of its xml:base attribute, resolved if it is relative against the base URI of the xsl:copy instruction.

Comment 4 Michael Kay 2010-05-13 16:45:24 UTC
The change in comment #3 was approved by the WG. An erratum will be drafted.
Comment 5 Michael Kay 2010-07-15 08:54:21 UTC
Erratum E42 will be raised as described in comment #3
Comment 6 Tim Mills 2010-07-20 16:04:42 UTC
Thanks.