Reputation: 2069
I am using an xslt transformation to transform some xml files. In order to format the output, what i am using is two tags in the xsl style sheet.
<xsl:output method="xml" indent="yes"/>
<xsl:strip-space elements="*"/>
But the problem is , in windows i am getting a kind of output , and when i run the program in a unix machine, i am getting a different kind of output. eg:
<Book name="Godfather" author="MarioPuzo"
/>
But in unix, what i am getting is ,
<Book author="MarioPuzo" name="Godfather" />
it is kind of a weird problem. Any help is appreciated.
Upvotes: 1
Views: 1625
Reputation: 243449
In XML there is no standard ordering defined in the set of the attributes of an element -- this can be different from implementation to implementation.
Also, in case the only difference between two XML documents is the order of attributes, they are considered "equal" -- for example the XPath 2.0 function deep-equal($doc1, $doc2) produces true().
This is analogous to a class definition -- two class definitions in which the only difference is the ordering of the properties (or methods) are the same class definition and can be substituted with each other without causing different result from any program that uses instances of this class definition.
Here is a demo of the fact that two documents are considered "equal" if the only differences are ordering of attributes:
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:variable name="vDoc2">
<t y="2" x="1" />
</xsl:variable>
<xsl:template match="/">
<xsl:sequence select="deep-equal(/, $vDoc2)"/>
</xsl:template>
</xsl:stylesheet>
When this transformation is applied on the following XML document:
<t x="1" y="2"/>
the result is:
true
Even if some hack is found for the attributes to appear in a particular order for a given implementation both of an XML parser and of an XSLT processor), this hack is not guaranteed to work with the next version of this implementation.
Upvotes: 1