Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Newbie: Can an XML file be sorted and retain XML format?

Status
Not open for further replies.

SpeedyDude

IS-IT--Management
May 27, 2003
12
0
0
US
I am using the Cisco Attendent Console to export a "master" list of names and phone numbers and then I deploy it to several users. I created the original file by parsing a spreadsheet and creating the proper XML file. That worked great. Then they updated the master, but the master does not put them in alphabetical order. bad deal when there are hundreds of speed dials in each group. What I would like to do is process and XML file and sort it on "name" based on the "speeddialgroup" as there are several speed dial groups and output the XML in the same fomrat so it can be copied to all the other users and imported into the Cisco Attendent Console progam. Here is a sample XML with 3 entries in group "A" and 2 in group "B".

I am not a XML or XSL programmer, more of a network administrator, so any assitance would be great. I have done some playing around with Saxon, but the output is not in XML format so it can be imported from the other users.

Thanks in advance.

Sample XML File:

<?xml version="1.0" encoding="UTF-8"?>
<AttendantConsoleUserSettings user="user">
<SavedAt timestamp = "Mon Jul 24 15:43:04 CDT 2006"/>
<SpeedDialGroup name="A">
<SpeedDialEntry><Name>All American Bank</Name><TelephoneNumber>913035551111</TelephoneNumber></SpeedDialEntry>
<SpeedDialEntry><Name>AAA Big Bank</Name><TelephoneNumber>917145552222</TelephoneNumber></SpeedDialEntry>
<SpeedDialEntry><Name>AAFES MO</Name><TelephoneNumber>919135553333</TelephoneNumber></SpeedDialEntry></SpeedDialGroup>
<SpeedDialGroup name="B"><SpeedDialEntry><Name>Big Bank of NY</Name><TelephoneNumber>917075554444</TelephoneNumber></SpeedDialEntry>
<SpeedDialEntry><Name>Bob's Bank</Name><TelephoneNumber>918455556666</TelephoneNumber></SpeedDialEntry></SpeedDialGroup>

There is a bunch of other stuff, but i can append that to the end if i can get the XML sorted.
 
This is one way to get it done.
[tt]
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="<xsl:eek:utput method="xml" encoding="utf-8" indent="yes" />
<xsl:template match="/">
<xsl:apply-templates />
</xsl:template>
<xsl:template match="node()[local-name()='SpeedDialGroup']">
<xsl:copy>
<xsl:copy-of select="@*" />
<xsl:apply-templates select="node()">
<xsl:sort select="Name" lang="en" order="ascending" data-type="text" />
</xsl:apply-templates>
</xsl:copy>
</xsl:template>

<xsl:template match="node()|@*|processing-instruction()|comment()|text()">
<xsl:copy>
<xsl:apply-templates select="node()|@*|processing-instruction()|comment()|text()" />
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top