Sorting XML file through multiple attributes

Posted by jbugeja on Stack Overflow See other posts from Stack Overflow or by jbugeja
Published on 2010-06-05T10:36:57Z Indexed on 2010/06/05 10:42 UTC
Read the original article Hit count: 199

Filed under:
|

I want to sort a 'free-form' XML file through multiple attributes (first by T and then by L). The XML is a bit complex and it is structured as shown below:

<?xml version="1.0" encoding="utf-8"?>
<wb xmlns:cf="http://www.macromedia.com/2004/cfform" xmlns:a="urn:dummy">
  <a:form name="chart">
    <a:fieldset FIELD="a" FIELDNAME="FieldSet1">
      <a:select1 FIELDNUMBER="01" L="1" T="2" />
      <a:input FIELDNUMBER="02" INDEX="4" L="200" T="1" />
    </a:fieldset>
    <a:fieldset FIELD="b" FIELDNAME="FieldSet1">
      <a:select1 FIELDNUMBER="03" T="3" L="1" />
      <a:input FIELDNUMBER="04" INDEX="7" T="4" L="200" />
      <a:fieldset FIELD="c" FIELDNAME="FieldSet1">
        <a:input FIELDNUMBER="05" T="10" INDEX="6" L="400" />
        <a:input FIELDNUMBER="06" T="8" INDEX="8" L="200" />
      </a:fieldset>
    </a:fieldset>
    <a:input FIELDNUMBER="08" INDEX="3" L="3" T="5" />
    <a:input FIELDNUMBER="09" INDEX="2" L="2" T="4" />
  </a:form>
</wb>

PS:

  1. The root element is wb and this is always followed by a:form
  2. The L and T are always found in elements that have a tag in the namespace a, the only exception being a:fieldset which does not have L and T
  3. a:fieldset could have multiple children of the namespace a including another a:fieldset

We can also assume that L denotes Left and T denotes Top. So, the idea of this is that when I view the transformed XML I can immediately note which elements precede what.

What's your take on this?

© Stack Overflow or respective owner

Related posts about Xml

Related posts about xsl