mfwebteam
asked on
Simple DOM Question plus XML Sort
We're fairly new to XML so any help appreciated (we are using online help and docs etc but have a fairly sharp timeline...)
We have some XML:
<Press_Components>
<Component ID="1">
<Content>
<title>This is the Title of the News Article A</title>
<ReleaseDate>
<day>15</day>
<month>04</month>
<year>2004</year>
<time>
<hour>08</hour>
<minute>00</minute>
<zone>UK</zone>
</time>
</ReleaseDate>
<Synopsis>This is the synopsis 1</Synopsis>
</Content>
<Categories>
<Category Title="BIA">Agility</Categ ory>
</Categories>
</Component>
<Component ID="2">
<Content>
<title>This is the Title of the News Article B</title>>
<ReleaseDate>
<day>15</day>
<month>04</month>
<year>2004</year>
<time>
<hour>08</hour>
<minute>00</minute>
<zone>UK</zone>
</time>
</ReleaseDate>
<Synopsis>This is the synopsis 2</Synopsis>
</Content>
<Categories>
<Category Title="BIA">Cost Reduction</Category>
<Category Title="Solution">Developme nt</Catego ry>
<Category Title="Industry">Financial Services</Category>
</Categories>
</Component>
<Press_Components>
We have some DOM code in ASP.
'Output All events in the XML
Response.Write "<h2>All Events </h2>"
For each oNode in oDom.SelectNodes("//Compon ent")
Response.Write oNode.GetAttribute("ID") & " - "
Response.Write oNode.getElementsByTagName ("title"). item(0).te xt & " - <br/>"
Response.Write oNode.getElementsByTagName ("Synopsis ").item(0) .text & " - <br/><br/>"
Next
This works but is this the correct/best way to get these elements.
In terms of a sort, how would we use XSL to sort the components so that they came out in reverse order of ReleaseDate - Year, Month, Day, Hour, Minutes... (hour will be 24 hour clock).
Many thanks
We have some XML:
<Press_Components>
<Component ID="1">
<Content>
<title>This is the Title of the News Article A</title>
<ReleaseDate>
<day>15</day>
<month>04</month>
<year>2004</year>
<time>
<hour>08</hour>
<minute>00</minute>
<zone>UK</zone>
</time>
</ReleaseDate>
<Synopsis>This is the synopsis 1</Synopsis>
</Content>
<Categories>
<Category Title="BIA">Agility</Categ
</Categories>
</Component>
<Component ID="2">
<Content>
<title>This is the Title of the News Article B</title>>
<ReleaseDate>
<day>15</day>
<month>04</month>
<year>2004</year>
<time>
<hour>08</hour>
<minute>00</minute>
<zone>UK</zone>
</time>
</ReleaseDate>
<Synopsis>This is the synopsis 2</Synopsis>
</Content>
<Categories>
<Category Title="BIA">Cost Reduction</Category>
<Category Title="Solution">Developme
<Category Title="Industry">Financial
</Categories>
</Component>
<Press_Components>
We have some DOM code in ASP.
'Output All events in the XML
Response.Write "<h2>All Events </h2>"
For each oNode in oDom.SelectNodes("//Compon
Response.Write oNode.GetAttribute("ID") & " - "
Response.Write oNode.getElementsByTagName
Response.Write oNode.getElementsByTagName
Next
This works but is this the correct/best way to get these elements.
In terms of a sort, how would we use XSL to sort the components so that they came out in reverse order of ReleaseDate - Year, Month, Day, Hour, Minutes... (hour will be 24 hour clock).
Many thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks Yury. That works well. One final thing. I've adjusted the XSL slightly but want to put a space between the Date and Time (e.g. 2004-04-15 08:00) - see below. How is that done?
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:param name="comp_order" select="'descending'" /> <!-- for ascending -->
<xsl:template match="/">
<html>
<body>
<h2>All Events </h2>
<xsl:apply-templates select="//Component">
<xsl:sort select="Content/ReleaseDat e/year" order="{$comp_order}" />
<xsl:sort select="Content/ReleaseDat e/month" order="{$comp_order}" />
<xsl:sort select="Content/ReleaseDat e/day" order="{$comp_order}" />
<xsl:sort select="Content/ReleaseDat e/time/hou r" order="{$comp_order}" />
<xsl:sort select="Content/ReleaseDat e/time/min ute" order="{$comp_order}" />
</xsl:apply-templates>
</body>
</html>
</xsl:template>
<xsl:template match="Component">
<strong>ID: </strong><xsl:value-of select="@ID" /><br />
<strong>Date: </strong><xsl:value-of select="Content/ReleaseDat e/year" />-<xsl:value-of select="Content/ReleaseDat e/month" />-<xsl:value-of select="Content/ReleaseDat e/day" /> <xsl:value-of select="Content/ReleaseDat e/time/hou r" />:<xsl:value-of select="Content/ReleaseDat e/time/min ute" /> <br />
<strong>Title: </strong><xsl:value-of select="Content/title" /><br/>
<strong>Synopsis: </strong><xsl:value-of select="Content/Synopsis" /> - <br/><br/>
</xsl:template>
</xsl:stylesheet>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:param name="comp_order" select="'descending'" /> <!-- for ascending -->
<xsl:template match="/">
<html>
<body>
<h2>All Events </h2>
<xsl:apply-templates select="//Component">
<xsl:sort select="Content/ReleaseDat
<xsl:sort select="Content/ReleaseDat
<xsl:sort select="Content/ReleaseDat
<xsl:sort select="Content/ReleaseDat
<xsl:sort select="Content/ReleaseDat
</xsl:apply-templates>
</body>
</html>
</xsl:template>
<xsl:template match="Component">
<strong>ID: </strong><xsl:value-of select="@ID" /><br />
<strong>Date: </strong><xsl:value-of select="Content/ReleaseDat
<strong>Title: </strong><xsl:value-of select="Content/title" /><br/>
<strong>Synopsis: </strong><xsl:value-of select="Content/Synopsis" /> - <br/><br/>
</xsl:template>
</xsl:stylesheet>
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks Yury and dualsoul.
Dualsole - accepted Yury's as the main answer but given you 20 points for the simpler question.
Thanks for your help
Dualsole - accepted Yury's as the main answer but given you 20 points for the simpler question.
Thanks for your help
Response.Write oNode.SelectSingleNode("ti
Response.Write oNode.SelectSingleNode("Sy