Bug #4937

Extra NS declaration added by transformer

Added by Taras Chervinka 6 months ago. Updated 5 months ago.

DOM Interface
Start date:
Due date:
% Done:


Estimated time:
Legacy ID:
Applies to branch:
10, trunk
Fix Committed on Branch:
10, trunk
Fixed in Maintenance Release:


<a xmlns='someNS' name='test'><b xmlns=''/></a>

is transformed into

<a xmlns='someNS' name='test'><b xmlns='' xmlns=''/></a>

which is not valid

org.xml.sax.SAXParseException; lineNumber: 2; columnNumber: 24; Attribute "xmlns" was already specified for element "b".

see test case attached. That works fine with 9.9 (HE, EE)

java -cp saxon9he.jar;.  testSaxonTransformer

but fails with 10.0-10.3 (HE, EE) also tried with EE 10.4

java -cp saxon-he-10.3.jar;.  testSaxonTransformer

but the transformed is correct when I add another NS. Like:

<a xmlns='someNS' xmlns:z='z' name='test'><b xmlns=''/></a> (1.54 KB) Taras Chervinka, 2021-03-15 14:36


#1 Updated by Michael Kay 6 months ago

  • Category set to DOM Interface
  • Status changed from New to In Progress
  • Assignee set to Michael Kay
  • Priority changed from Low to Normal
  • Applies to branch trunk added

Thanks for reporting it.

Reproduced as JUnit test testNamespaceSerializationBug4937().

#2 Updated by Michael Kay 6 months ago

The error appears to be when combining two namespace maps (NamespaceMap.applyDifferences() -- which is not actually DOM-specific code, though it's probably used rather differently when handling DOM input.). This ends up incorrectly generating an empty namespace map for element b, rather than a map containing the single namespace binding (""=""). This error is then compounded: because the namespace map is empty, the scan of attributes on element b doesn't check whether any of the attributes are actually namespaces, so it's processing xmlns:"" a second time as if it were an ordinary attribute.

#3 Updated by Michael Kay 6 months ago

I've applied a fix to NamespaceMap.applyDifferences() on the 10.x branch which ensures this test now passes. However, the test passes on the 11.x branch without this change: I'm currently exploring why.

#4 Updated by Michael Kay 6 months ago

  • Status changed from In Progress to Resolved
  • Fix Committed on Branch 10, trunk added

It was working on the 11.x branch because my configuration settings meant I was picking up Xalan as the DOM identityTransformer. Fixed this, found the bug was still present, so I've applied the patch to both branches.

#5 Updated by O'Neil Delpratt 5 months ago

  • Status changed from Resolved to Closed
  • % Done changed from 0 to 100
  • Fixed in Maintenance Release 10.5 added

Bug fix applied to Saxon 10.5 maintenance release.

Please register to edit this issue

Also available in: Atom PDF