Link to home
Start Free TrialLog in
Avatar of lfwebz
lfwebz

asked on

XML file - regenerate/recreate after reorder

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

Avatar of zc2
zc2
Flag of United States of America image

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

Avatar of lfwebz
lfwebz

ASKER

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

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()">
Avatar of lfwebz

ASKER

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

So, what does the browser show if you load the original xml into it?
Avatar of lfwebz

ASKER

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.
ASKER CERTIFIED SOLUTION
Avatar of zc2
zc2
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of lfwebz

ASKER

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.
Avatar of lfwebz

ASKER

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.
You're welcome and I'm sorry I could not help fully resolve the issue