PDA

View Full Version : Sort XML to XML with no stylesheet


NJCapeAdmin
08-28-2009, 08:16 PM
I have been trying to figure this out for a week, searched Google many times
- read tons of articles - I just can't get this to work. I have an XML file
which is generated by an application we use. This XML file loads data into
a form for the application. the application was written poorly and does not
allow sorting of the columns on the form. This makes using the form very
difficult as I need to look through over 500 entries 3 at a time (all the
form will allow you to display). My goal is to be able to sort this XML
file so that when the form is opened the entries are sorted already,
making looking for a particular entry much easier. I cannot change the
way the app uses the XML so I need to sort the XML file and then place
it back into the App folder sorted. I tested this by manually sorting 2
entries in notepad and it does work, but sorting 500+ entries manually
is not feasible. Ok now here is an example of my XML file listed below:

<bunch of stuff before the section I need sorted>

<mailboxes>

<mailbox>
<pop_server>111.222.333.444</pop_server>
<login>username4</login>
<password>********</password>
<alternate_address>username4@emailserver</alternate_address>
<send_to>alternate</send_to>
</mailbox>

<mailbox>
<pop_server>111.222.333.444</pop_server>
<login>username2</login>
<password>********</password>
<alternate_address>username2@emailserver</alternate_address>
<send_to>alternate</send_to>
</mailbox>

<mailbox>
<pop_server>111.222.333.444</pop_server>
<login>username1</login>
<password>********</password>
<alternate_address>username1@emailserver</alternate_address>
<send_to>alternate</send_to>
</mailbox>

</mailboxes>

<bunch of stuff at the end>



I wish to have this sorted by the ALTERNATE_ADDRESS portion of the data.
I have read so many posts and tried to adapt so many pieces of code to
fit my needs, but I just can't get this to work. I am a Network Engineer
who dabbles in code every now and then, but I am certainly not a programmer,
so please try to post in as simple terms as possible.

Thanks to anyone who may take the time to read this post, or that tries to
help me out - I really do appreciate the time & effort.

ckeyrouz
08-28-2009, 09:21 PM
I created a sample xsl file for you and a sample xml file with the same structure that you have.

All you have to do is open the xml file in your browser then view source and copy the xml and paste it in your text editor and save it:

note that in the attached xsl file there is the line:

<xsl:sort data-type="text" order="ascending" select="pop_server"/>

you can change the order to ascending and descending

you can change the data-type to number or text

the select attribute should contain the name of the node that you wish to sort accordingly.

Note that the data-type and the select field should match.

you cannot put inside the select a node that has text content and data-type as number.

Hope this helps.

jamanda
09-09-2009, 11:40 PM
Hi,

I'm in a similar boat to NJCapeAdmin and need to get data in a drop down list sorted. I've got my XML & XSL files but the XSL:sort isn't working. Any chance of getting a copy of the two example files you created please so that I can compare with mine to see what I've done wrong?

Cheers,
AJ

ckeyrouz
09-11-2009, 06:35 AM
Yes sure.
Am now at home.

Tomorrow I will send them to you when I go to work.

jamanda
09-11-2009, 06:53 AM
Hi,

Thanks for that, however, I'm all sorted now. It wasn't my code, it's something to do with the way the google maps API works that makes it ignore my stylesheet. Am now investigating ways around this. :)

Cheers,
AJ