Project

Profile

Help

Bug #6057

closed

xquery copy attributes fails

Added by Khalil Rahmouni over 1 year ago. Updated over 1 year ago.

Status:
Rejected
Priority:
Normal
Assignee:
-
Category:
-
Sprint/Milestone:
-
Start date:
2023-06-01
Due date:
% Done:

0%

Estimated time:
Legacy ID:
Applies to branch:
Fix Committed on Branch:
Fixed in Maintenance Release:
Platforms:
Java

Description

we use a similar code to the following to copy element and attributes with xquery, it works fine with 9.7 but it fails with 11.5 ee version with the following exception net.sf.saxon.trans.XPathException: Cannot copy attributes whose type is namespace-sensitive (QName or NOTATION): @n1:type If i remove the validation then it works .


Files

first.xq (447 Bytes) first.xq Khalil Rahmouni, 2023-06-01 18:43
first.xml (355 Bytes) first.xml Khalil Rahmouni, 2023-06-01 18:43
first.xsd (608 Bytes) first.xsd Khalil Rahmouni, 2023-06-01 18:43
simple.xsd (449 Bytes) simple.xsd Khalil Rahmouni, 2023-06-01 18:43
Actions #1

Updated by Martin Honnen over 1 year ago

Somehow Saxon (tested with 10.9 EE, 11.5 EE and 12.2 EE) doesn't even manage to validate the first.xml against the schema first.xsd, giving errors like

Validation error on line 3 column 71 of first.xml:
  XQDY0084: Cannot validate <Q{.../meinnamespace.meinefirma.de}MeinRootElement>: no element
  declaration available
  See http://www.w3.org/TR/xmlschema-1/#cvc-elt clause 1
Validation error on line 6 column 38 of first.xml:
  FONS0004: Namespace prefix {n2} has not been declared
  See http://www.w3.org/TR/xmlschema-1/#cvc-complex-type clause 3
Error on line 9 column 19 of first.xml:
  XQDY0084  Two validation errors were reported. First error: Cannot validate
  <Q{.../meinnamespace.meinefirma.de}MeinRootElement>: no element declaration available
Validation complete: errors found

I don't know whether that is related to the XQuery error/bug I am not sure.

Wait for Michael Kay to tell you more.

Actions #2

Updated by Michael Kay over 1 year ago

I think Saxon is behaving correctly by raising this error.

I guess this was error code XQTY0086, and locating that error code in the XQuery spec may shed some insight. The equivalent error in XSLT is XTTE0950. I prefer the explanation there (because I wrote it):

When attribute nodes are copied, whether with xsl:copy or with xsl:copy-of, the processor does not automatically copy any associated namespace information. The namespace used in the attribute name itself will be declared by virtue of the namespace fixup process (see 5.7.3 Namespace Fixup) when the attribute is added to an element in the result tree, but if namespace prefixes are used in the content of the attribute (for example, if the value of the attribute is an XPath expression) then it is the responsibility of the stylesheet author to ensure that suitable namespace nodes are added to the result tree. This can be achieved by copying the namespace nodes using xsl:copy, or by generating them using xsl:namespace.

You're copying the xsi:type attribute, whose value is a QName, to a new element. Generally you can copy any validated subtree to a new parent tree and it will remain valid, so it can retain its type annotations. But the validity of a QName depends on the in-scope namespaces, so that isn't guaranteed in this case: it can be valid in its old location, and not valid in the new location. If you copied the containing element, that would work, because it would copy the namespaces, but copying the attribute without the namespaces creates the risk of leaving things inconsistent.

Saxon 9.7 is quite a while ago; I would have to do some digging to determine the detail, but this change is almost certainly a bug fix, quite possibly in response to a bug being fixed during XSLT/XQuery standards development.

Actions #3

Updated by Khalil Rahmouni over 1 year ago

even if i copy the namespace, i still get the same error. copying the hole element works fine but we want to have an element with the same structure of the original element but with a different name.

Actions #4

Updated by Michael Kay over 1 year ago

I would suggest that instead of copying the attribute, you create a new one, something like

attribute('xsi:type'}{$valid/*/string(@*))

so the type annotation isn't a distraction.

Actions #5

Updated by Michael Kay over 1 year ago

  • Status changed from New to Rejected

I'm closing this because there is no bug: Saxon is doing what the spec says.

Please register to edit this issue

Also available in: Atom PDF