Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 17th, 2012, 10:06 AM
Authorized User
 
Join Date: Apr 2011
Posts: 22
Thanks: 4
Thanked 0 Times in 0 Posts
Default attributes auto ordering

Hi Masters,
I am using saxon 9.

When I create an element in XSLT like this,
Code:
<xsl:template match="/">
        <w:document mc:Ignorable="w14 wp14" xmlns:wpc="http://schemas.microsoft.com/office/word/2010/wordprocessingCanvas" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" xmlns:m="http://schemas.openxmlformats.org/officeDocument/2006/math" xmlns:v="urn:schemas-microsoft-com:vml">
<some code...../>
</w:document>
When the input XML is transformed using this XSL, the output contains the required elements, but the order of the attributes (namespaces) is changed and order randomly.

Code:
<w:document xmlns:wpc="http://schemas.microsoft.com/office/word/2010/wordprocessingCanvas" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" xmlns:m="http://schemas.openxmlformats.org/officeDocument/2006/math" xmlns:v="urn:schemas-microsoft-com:vml" mc:Ignorable="w14 wp14">
<some code...../>
</w:document>
Though this doesn't harm anything, I am not able to see the required output in Word.

Can someone help me on how to retain the order of the attributes as mentioned in the XSL?
 
Old January 17th, 2012, 10:32 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

That's not usually possible (although I can't swear to it).
Why would you want to, attribute ordering is not relevant in an XML document?
__________________
Joe
http://joe.fawcett.name/
 
Old January 17th, 2012, 10:36 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

Sorry, I didn't see that you meant the namespace declarations (which are no counted as attributes). However the same argument applies, the ordering of them is irrelevant. I would be very surprised if Word needed them in a certain order as this is contrary to the XML Namespaces specifications.
__________________
Joe
http://joe.fawcett.name/
 
Old January 17th, 2012, 12:48 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

XSLT itself gives you no way of controlling attribute order, and neither does Saxon (unless you write Java code to customize the serializer -- which is definitely possible). The order of attributes is cosmetic only (but I have some sympathy, because serialized output is supposed to be human readable, and this can contribute to readability.)
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference





Similar Threads
Thread Thread Starter Forum Replies Last Post
Display HTML Attributes from XML Attributes rangeshram XSLT 3 March 27th, 2010 01:14 PM
Re-ordering values mitchcohen XSLT 2 April 23rd, 2009 02:40 PM
Ordering results EstherMStrom XSLT 6 October 13th, 2004 09:50 AM
alternate ordering polecat XSLT 17 October 2nd, 2003 08:35 AM
Ordering lists POL XSLT 3 June 9th, 2003 11:39 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.