Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

XML file - regenerate/recreate after reorder

Posted on 2013-05-16
10
Medium Priority
?
310 Views
Last Modified: 2013-05-16
I have a RSS feed, that I need to reorder for a client. I need to reorder the xml file, not the output(of course the output would be reordered as  the xml contents are reordered). So to be clear, it is not the output of the xml file that I am focused on, but the contents of the xml file. See examples below:

Here is my xml file:

<?xml-stylesheet type="text/xsl" href="tdome_trans2.xsl" ?>
<rss version="2.0">
<channel>
<title>Thunder Dome - Calendar - Villiage Ctr</title>
<link>https://www.??????/?????.aspx</link>
<update>Wed, 15 June 2013 09:30 -0500</update>
<location>Thunder Dome - Upcoming Events</location>
<language>en-us</language>
<item>
<title>Event 1</title>
<link>https://www.??????/?????.aspx</link>
<pubDate>Wed, 15 June 2013 08:46 -0500</pubDate>
<location>June 29, 2013, 8:00 AM, Town Square</location>
<guid>https://www.??????/?????.aspx</guid>
</item>
<item>
<title>Event 2</title>
<link>https://www.??????/?????.aspx</link>
<pubDate>Wed, 15 June 2013 08:43 -0500</pubDate>
<location>June 23, 2013, 6:00 PM, Danny's Bar and Grill</location>
<guid>https://www.??????/?????.aspx</guid>
</item>
<item>
<title>Event 3</title>
<link>https://www.??????/?????.aspx</link>
<pubDate>Wed, 15 June 2013 08:43 -0500</pubDate>
<location>June 21, 2013, 7:00 PM, Auditoriam</location>
<guid>https://www.??????/?????.aspx</guid>
</item>
<item>
<title>Event 4</title>
<link>https://www.??????/?????.aspx</link>
<pubDate>Wed, 15 June 2013 09:30 -0500</pubDate>
<location>June 20, 2013, 6:30 PM, Grarage</location>
<guid>https://www.??????/?????.aspx</guid>
</item>
<item>
<title>Event 5</title>
<link>https://www.??????/?????.aspx</link>
<pubDate>Wed, 15 June 2013 09:30 -0500</pubDate>
<location>June 05, 2013, 6:30 PM, Garage Bar</location>
<guid>https://www.??????/?????.aspx</guid>
</item>
<item>
<title>Event 6</title>
<link>https://www.??????/?????.aspx</link>
<pubDate>Wed, 15 June 2013 09:30 -0500</pubDate>
<location>June 20, 2013, 6:30 PM, The Old Mansion</location>
<guid>https://www.??????/?????.aspx</guid>
</item>
</channel>
</rss>

Open in new window


Here is my xsl file that reorders based on the location
<?xml version="1.0"  encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output indent="yes" method="xml"/>
    <xsl:template match="*">
        <channel>
            <xsl:apply-templates select="channel"/>
        </channel>
    </xsl:template>

    <xsl:template match="channel">
        <xsl:apply-templates select="item">
            <xsl:sort select="location" order="ascending"/>
        </xsl:apply-templates>
    </xsl:template>

    <xsl:template match="item">
        <xsl:copy-of select="."/>
    </xsl:template>
</xsl:stylesheet>

Open in new window


here is the output via the browser:
Event 5 https://www.??????/?????.aspx Wed, 15 June 2013 09:30 -0500 June 05, 2013, 6:30 PM, Garage Bar https://www.??????/?????.aspx Event 4 https://www.??????/?????.aspx Wed, 15 June 2013 09:30 -0500 June 20, 2013, 6:30 PM, Grarage https://www.??????/?????.aspx Event 6 https://www.??????/?????.aspx Wed, 15 June 2013 09:30 -0500 June 20, 2013, 6:30 PM, The Old Mansion https://www.??????/?????.aspx Event 3 https://www.??????/?????.aspx Wed, 15 June 2013 08:43 -0500 June 21, 2013, 7:00 PM, Auditoriam https://www.??????/?????.aspx Event 2 https://www.??????/?????.aspx Wed, 15 June 2013 08:43 -0500 June 23, 2013, 6:00 PM, Danny's Bar and Grill https://www.??????/?????.aspx Event 1 https://www.??????/?????.aspx Wed, 15 June 2013 08:46 -0500 June 29, 2013, 8:00 AM, Town Square https://www.??????/?????.aspx

Open in new window


The output above is now in the order i want, but I want the xml file with the nodes ordered correctly so I want to re-generate the xml file so it appears like this, notice that I have manually reordered the contents to show as an example: (forgive me for restating so much, but I am learning this to get a client request completed by Friday). Any assistance is appreciated!!

<?xml-stylesheet type="text/xsl" href="tdome_trans2.xsl" ?>
<rss version="2.0">
<channel>
<title>Thunder Dome - Calendar - Villiage Ctr</title>
<link>https://www.??????/?????.aspx</link>
<update>Wed, 15 June 2013 09:30 -0500</update>
<location>Thunder Dome - Upcoming Events</location>
<language>en-us</language>
<item>
<title>Event 5</title>
<link>https://www.??????/?????.aspx</link>
<pubDate>Wed, 15 June 2013 09:30 -0500</pubDate>
<location>June 05, 2013, 6:30 PM, Garage Bar</location>
<guid>https://www.??????/?????.aspx</guid>
</item>
<item>
<title>Event 4</title>
<link>https://www.??????/?????.aspx</link>
<pubDate>Wed, 15 June 2013 09:30 -0500</pubDate>
<location>June 20, 2013, 6:30 PM, Grarage</location>
<guid>https://www.??????/?????.aspx</guid>
</item>
<item>
<title>Event 6</title>
<link>https://www.??????/?????.aspx</link>
<pubDate>Wed, 15 June 2013 09:30 -0500</pubDate>
<location>June 20, 2013, 6:30 PM, The Old Mansion</location>
<guid>https://www.??????/?????.aspx</guid>
</item>
<item>
<item>
<title>Event 3</title>
<link>https://www.??????/?????.aspx</link>
<pubDate>Wed, 15 June 2013 08:43 -0500</pubDate>
<location>June 21, 2013, 7:00 PM, Auditoriam</location>
<guid>https://www.??????/?????.aspx</guid>
</item>
<item>
<title>Event 2</title>
<link>https://www.??????/?????.aspx</link>
<pubDate>Wed, 15 June 2013 08:43 -0500</pubDate>
<location>June 23, 2013, 6:00 PM, Danny's Bar and Grill</location>
<guid>https://www.??????/?????.aspx</guid>
</item>
<title>Event 1</title>
<link>https://www.??????/?????.aspx</link>
<pubDate>Wed, 15 June 2013 08:46 -0500</pubDate>
<location>June 29, 2013, 8:00 AM, Town Square</location>
<guid>https://www.??????/?????.aspx</guid>
</item>
</channel>
</rss>

Open in new window

0
Comment
Question by:lfwebz
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 5
10 Comments
 
LVL 19

Expert Comment

by:zc2
ID: 39172048
I've redesigned your XSLT, please take a look

<?xml version="1.0"  encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output indent="yes" method="xml"/>

    <xsl:template match="channel">
      <channel>
      	<xsl:apply-templates select="*[name() != 'item']"/>
        <xsl:apply-templates select="item">
            <xsl:sort select="location" order="ascending"/>
        </xsl:apply-templates>
      </channel>
    </xsl:template>

    <xsl:template match="*">
        <xsl:copy>
        	<xsl:apply-templates select="@*|*|text()"/>
        </xsl:copy>
    </xsl:template>

    <xsl:template match="@*|text()">
        <xsl:copy/>
    </xsl:template>
</xsl:stylesheet>

Open in new window

0
 

Author Comment

by:lfwebz
ID: 39172127
Hi Zc2

Thank you for your input, but the problem is the output when I place tdome.xml in my browser is this:

Thunder Dome - Calendar - Villiage Ctrhttps://www.??????/?????.aspxWed, 15 June 2013 09:30 -0500Thunder Dome - Upcoming Eventsen-us Event 5 https://www.??????/?????.aspx Wed, 15 June 2013 09:30 -0500 June 05, 2013, 6:30 PM, Garage Bar https://www.??????/?????.aspx Event 4 https://www.??????/?????.aspx Wed, 15 June 2013 09:30 -0500 June 20, 2013, 6:30 PM, Grarage https://www.??????/?????.aspx Event 6 https://www.??????/?????.aspx Wed, 15 June 2013 09:30 -0500 June 20, 2013, 6:30 PM, The Old Mansion https://www.??????/?????.aspx Event 3 https://www.??????/?????.aspx Wed, 15 June 2013 08:43 -0500 June 21, 2013, 7:00 PM, Auditoriam https://www.??????/?????.aspx Event 2 https://www.??????/?????.aspx Wed, 15 June 2013 08:43 -0500 June 23, 2013, 6:00 PM, Danny's Bar and Grill https://www.??????/?????.aspx Event 1 https://www.??????/?????.aspx Wed, 15 June 2013 08:46 -0500 June 29, 2013, 8:00 AM, Town Square https://www.??????/?????.aspx

Open in new window


but the client needs the modified xml file which would display similar to this:

<?xml version="1.0" ?>
<rss version="2.0">
<channel>
<title>Thunder Dome - Calendar - Villiage Ctr</title>
<link>https://www.??????/?????.aspx</link>
<update>Wed, 15 June 2013 09:30 -0500</update>
<location>Thunder Dome - Upcoming Events</location>
<language>en-us</language>
<item>
<title>Event 5</title>
<link>https://www.??????/?????.aspx</link>
<pubDate>Wed, 15 June 2013 09:30 -0500</pubDate>
<location>June 05, 2013, 6:30 PM, Garage Bar</location>
<guid>https://www.??????/?????.aspx</guid>
</item>
<item>
<title>Event 4</title>
<link>https://www.??????/?????.aspx</link>
<pubDate>Wed, 15 June 2013 09:30 -0500</pubDate>
<location>June 20, 2013, 6:30 PM, Grarage</location>
<guid>https://www.??????/?????.aspx</guid>
</item>
<item>
<title>Event 6</title>
<link>https://www.??????/?????.aspx</link>
<pubDate>Wed, 15 June 2013 09:30 -0500</pubDate>
<location>June 20, 2013, 6:30 PM, The Old Mansion</location>
<guid>https://www.??????/?????.aspx</guid>
</item>

Open in new window

0
 
LVL 19

Expert Comment

by:zc2
ID: 39172179
May be because the first line withe processing instruction is missed in the output?
Please try to replace the line 20 of my XSLT with the following:

    <xsl:template match="@*|text()|processing-instruction()">
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:lfwebz
ID: 39172296
There must be something I am doing wrong. the browser output is still:

Thunder Dome - Calendar - Villiage Ctrhttps://www.??????/?????.aspxWed, 15 June 2013 09:30 -0500Thunder Dome - Upcoming Eventsen-us Event 5 https://www.??????/?????.aspx Wed, 15 June 2013 09:30 -0500 June 05, 2013, 6:30 PM, Garage Bar https://www.??????/?????.aspx Event 4 https://www.??????/?????.aspx Wed, 15 June 2013 09:30 -0500 June 20, 2013, 6:30 PM, Grarage https://www.??????/?????.aspx Event 6 https://www.??????/?????.aspx Wed, 15 June 2013 09:30 -0500 June 20, 2013, 6:30 PM, The Old Mansion https://www.??????/?????.aspx Event 3 https://www.??????/?????.aspx Wed, 15 June 2013 08:43 -0500 June 21, 2013, 7:00 PM, Auditoriam https://www.??????/?????.aspx Event 2 https://www.??????/?????.aspx Wed, 15 June 2013 08:43 -0500 June 23, 2013, 6:00 PM, Danny's Bar and Grill https://www.??????/?????.aspx Event 1 https://www.??????/?????.aspx Wed, 15 June 2013 08:46 -0500 June 29, 2013, 8:00 AM, Town Square https://www.??????/?????.aspx

Open in new window


I made the change in line 20

<?xml version="1.0"  encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output indent="yes" method="xml"/>

    <xsl:template match="channel">
      <channel>
      	<xsl:apply-templates select="*[name() != 'item']"/>
        <xsl:apply-templates select="item">
            <xsl:sort select="location" order="ascending"/>
        </xsl:apply-templates>
      </channel>
    </xsl:template>

    <xsl:template match="*">
        <xsl:copy>
        	<xsl:apply-templates select="@*|*|text()"/>
        </xsl:copy>
    </xsl:template>

    <xsl:template match="@*|text()|processing-instruction()">
        <xsl:copy/>
    </xsl:template>
</xsl:stylesheet>

Open in new window

0
 
LVL 19

Expert Comment

by:zc2
ID: 39172392
So, what does the browser show if you load the original xml into it?
0
 

Author Comment

by:lfwebz
ID: 39172414
if i remove this
<?xml-stylesheet type="text/xsl" href="tdome_trans4.xsl" ?>

Open in new window

from the original xml file and put in
<?xml version="1.0"  encoding="UTF-8"?>

Open in new window

, I see the xml broken out in it sections as nodes as I want to.  But the stylesheet is needed to pull in the xsl - is that correct.

I apologize for the ignorance on my part, I was literally handed this issue yesterday and the most i do with xml files is pull them in and display.  Never had to do anything like this before.
0
 
LVL 19

Accepted Solution

by:
zc2 earned 1400 total points
ID: 39172621
I'm sorry, I don't have anything more to suggest. The input and output files are identical (except the different sorting) and all the browsers I tried show them both the same way.

You may want also change the line 3 of the XSLT to this:

<xsl:output indent="yes" method="xml" omit-xml-declaration="yes"/>

It won't help, but since the input file did not have the XML declaration, so let's remove it from the output file as well.
0
 

Author Comment

by:lfwebz
ID: 39173110
Hi ZC2

Thanks so much for your help.  I went on and told the client it just couldn't be done and they needed to get their hosting provider to provide the correctly formatted xml.  i will try your suggestions, I am kind of curious now as to why this is not working.

Thanks again for all you imput.  I appreciate it.
0
 

Author Closing Comment

by:lfwebz
ID: 39173115
Was not able to resolve my specific issue, but really interesting, helpful feedback, particularly since I was learning at the same time as trying to get an unfamiliar project completed.   Thanks so much.
0
 
LVL 19

Expert Comment

by:zc2
ID: 39173122
You're welcome and I'm sorry I could not help fully resolve the issue
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The Problem How to write an Xquery that works like a SQL outer join, providing placeholders for absent data on the outer side?  I give a bit more background at the end. The situation expressed as relational data Let’s work through this.  I’ve …
The Client Need Led Us to RSS I recently had an investment company ask me how they might notify their constituents about their newsworthy publications.  Probably you would think "Facebook" or "Twitter" but this is an interesting client.  Their cons…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …

610 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question