2

I've created an XSLT stylesheet document. Within this document I create a new XML document as stated below:

...
<CREATE_REQ
            xsi:schemaLocation="http://fcubs.ofss.com/service/aServices theService.xsd"
            xmlns="http://fcubs.ofss.com/service/aServices"
            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
...

After transformation (see below) the ordering of the namespaces is different. A normal XML parser can handle this and it is normally no problem. The problem in my case is that the receiving application can't handle this and the order of the namespace may and shouldn't be changed.

<CREATE_REQ xmlns="http://fcubs.ofss.com/service/aServices"
            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
            xsi:schemaLocation="http://fcubs.ofss.com/service/aServices theService.xsd">

...

Is there a function or declaration that the namespaces will not be changed?

Eero Helenius
  • 2,584
  • 21
  • 22
Dirk
  • 121
  • 1
  • 7
  • 3
    With all due respect, it's the receiving application that is broken, not your code... If it claims to be using XML as its interchange format then it should use a proper parser and not try to enforce rules that XML tools can't guarantee. [This answer](http://stackoverflow.com/a/726933/592139) puts it much more eloquently than I can. – Ian Roberts Mar 04 '13 at 23:23

2 Answers2

4

If the receiving application can't handle it then it needs to be fixed. Whoever wrote it doesn't seem to have grasped what XML is all about. Fix the receiving application, or throw it in the bin where it belongs.

Michael Kay
  • 156,231
  • 11
  • 92
  • 164
1

After transformation (see below) the ordering of the namespaces is different.

No, the ordering is exactly the same. According to the W3C XPath 1.0 Data Model:

The attribute nodes and namespace nodes of an element occur before the children of the element. The namespace nodes are defined to occur before the attribute nodes.

This means that although in the provided XML fragment the attribute xmlns:xsi seems to precede the namespace declarations, in fact it follows them.

Therefore, the produced output doesn't change the ordering of namespaces and attributes of the original XML document.

Producing an XML document where an attribute precedes a namespace node would violate the above quoted definition, therefore a compliant XSLT processor wouldn't produce such a document.

Dimitre Novatchev
  • 240,661
  • 26
  • 293
  • 431