1

I am using "Attribute Value Templates" to transform and XML into another XML format. This is my XSLT:-

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    exclude-result-prefixes="xsi"
    xmlns:ted="Report1"
    >
<xsl:output method="xml" indent="yes" encoding="utf-8" />


    <xsl:template match="/ted:Report">

        <xsl:variable name="VersionNumber" select="ted:TUserInput/ted:Details_Collection/ted:Details/@VersionNumber" />
        <xsl:variable name="Date1" select="ted:TUserInput/ted:Details_Collection/ted:Details/@Date1" />
        <xsl:variable name="Date2" select="ted:TUserInput/ted:Details_Collection/ted:Details/@Date2"/>

        <Root XSDVersion="{$XSDVersion}">
                <Body>
                    <Intro VersionNumber="{$VersionNumber}"
                                 Date1="{$Date1}}"
                                 Date2="{$Date2}"/>                 
                </Body>
        </Root>
    </xsl:template>

The transformation is happening however I have notices that the elements into the "Intro" tag are not being outputted into the order specified in the XSLT. E.g. VersionNumber, Date1 and Date2 but in a different order like sthe below:-

<?xml version="1.0" encoding="UTF-8"?>
   <Root xmlns:ted="Report1" XSDVersion="01"> 
      <Body>
         <Intro Date2="2017-09-04" Date1="2017-09-13T13:57:16.86"   VersionNumber="4"/></Body>
   </Root>

What could it be that is causing this issue?

kjhughes
  • 106,133
  • 27
  • 181
  • 240
user2307236
  • 665
  • 4
  • 19
  • 44
  • I can't understand why this is related to reporting services – niktrs Sep 13 '17 at 12:05
  • 1
    In XML the order of attributes is arbitrary and cannot be controlled. – zx485 Sep 13 '17 at 12:06
  • Thank you i didn't know that. But will the output XML validate against an XSD where the attributes are defined in a different order? – user2307236 Sep 13 '17 at 12:12
  • It is at the core of XML that attribute ordering doesn't matter; XSD will not (cannot) care either. See [**Setting the order of attributes for XML in XSD (XML Schema)**](https://stackoverflow.com/questions/19263907/setting-the-order-of-attributes-for-xml-in-xsd-xml-schema) – kjhughes Sep 13 '17 at 12:25
  • Ok thank you for you clarifications. – user2307236 Sep 13 '17 at 12:32

0 Answers0