BaseXdb / basex

BaseX Main Repository.
http://basex.org
BSD 3-Clause "New" or "Revised" License
661 stars 268 forks source link

Bogus namespace conflict when renaming attributes #2205

Closed brandes-pq closed 1 year ago

brandes-pq commented 1 year ago

Description of the Problem

When renaming non-prefixed attributes using the update facility, an XUDY0023 error ("namespace conflict") is triggered if the containing element is living in a (non-empty) default namespace.

Example:

<foo xmlns="urn:x" bar="2" />

transform with {
  for $a in .//@bar return rename node $a as 'baz' 
}

(: yields [XUDY0023] Namespace conflicts: baz vs. Q{urn:x}. :)

Expected Behavior

Since attributes are not affected by default namespace declarations, there is no conflict here; no error should be triggered. The expected result is

<foo xmlns="urn:x" baz="2" />

Steps to Reproduce the Behavior

The query above directly demonstrates the behvior.

For further consideration:

It is possible to write the desired transformation by using replace instead of rename. The following query works without error and may be used as a workaround:

<foo xmlns="urn:x" bar="2" /> 

transform with {
  for $a in .//@bar return replace node $a with attribute {'baz'} { $a } 
}

Correctly returns

<foo xmlns="urn:x" baz="2" />

Do you have an idea how to solve the issue?

Renaming attribute nodes must probably be special-cased, as the usual assumptions about declared default namespaces do not apply to them.

What is your configuration?

BaseX 10.5

ChristianGruen commented 1 year ago

Thanks for the observation. You’re right, the query shouldn’t raise an error.