Jump to content

Sorting The Data From Xml File In Descending Order


anujojha
 Share

Recommended Posts

Hi guys I want to sort and print the data from xml file in descending order. I tried it using xsl:sort but thats not working.I am pasting the code below please help me figure out how to do it.... xml

<?xml version="1.0" encoding="utf-8"?><ListItems>  <ListItem>    <Attachments>False</Attachments>    <LinkTitle>Ahello</LinkTitle>    <desc>To read more Click </desc>    <image href="/Communities/Directorates/Logistics/Newpage/images/New1.JPG">    </image>    <more href="/pa/apr09expo.pdf">more</more>    <FileRef>/Communities/Directorates/Logistics/Lists/news/1_.000</FileRef>    <FileDirRef>Communities/Directorates/Logistics/Lists/news</FileDirRef>    <FileLeafRef>1_.000</FileLeafRef>    <ServerUrl>/Communities/Directorates/Logistics/Lists/news/1_.000</ServerUrl>    <BaseName>1_</BaseName>    <ID>1</ID>    <_ModerationStatus>0</_ModerationStatus>    <_Level>1</_Level>    <owshiddenversion>1</owshiddenversion>    <UniqueId>00721fc7-4e47-4d1e-b48e-4ab5cab12730</UniqueId>    <FSObjType>0</FSObjType>    <Created_x0020_Date>8/5/2009 8:26</Created_x0020_Date>    <Created>8/5/2009 1:26:24 PM</Created>  </ListItem>  <ListItem>    <Attachments>False</Attachments>    <LinkTitle>Recycling Programs</LinkTitle>    <desc>D </desc>    <image href="/Communities/Directorates/Logistics/Newpage/images/lgSusLogo2.jpg">    </image>    <more href="/sites/9/FMO/Newletter/LG%20Newletter%20-%20June%2009.1.pdf">more</more>    <FileRef>/Communities/Directorates/Logistics/Lists/news/2_.000</FileRef>    <FileDirRef>Communities/Directorates/Logistics/Lists/news</FileDirRef>    <FileLeafRef>2_.000</FileLeafRef>    <ServerUrl>/Communities/Directorates/Logistics/Lists/news/2_.000</ServerUrl>    <BaseName>2_</BaseName>    <ID>2</ID>    <_ModerationStatus>0</_ModerationStatus>    <_Level>1</_Level>    <owshiddenversion>7</owshiddenversion>    <UniqueId>fd24ae04-5f2c-4c96-b2a3-9f5f8032ce2b</UniqueId>    <FSObjType>0</FSObjType>    <Created_x0020_Date>8/5/2009 9:08</Created_x0020_Date>    <Created>8/5/2009 2:08:25 PM</Created>  </ListItem>  <ListItem>    <Attachments>False</Attachments>    <LinkTitle>the Warehouse</LinkTitle>    <desc> To read more click </desc>    <image href="/Communities/Directorates/Logistics/Newpage/images/New3.JPG">    </image>    <more href="/C17/Project%20WMS/Newsletters/WMS%20Let%27s%20Move%20It!%20Special%20Edition.pdf">more</more>    <FileRef>/Communities/Directorates/Logistics/Lists/news/3_.000</FileRef>    <FileDirRef>Communities/Directorates/Logistics/Lists/news</FileDirRef>    <FileLeafRef>3_.000</FileLeafRef>    <ServerUrl>/Communities/Directorates/Logistics/Lists/news/3_.000</ServerUrl>    <BaseName>3_</BaseName>    <ID>3</ID>    <_ModerationStatus>0</_ModerationStatus>    <_Level>1</_Level>    <owshiddenversion>3</owshiddenversion>    <UniqueId>47c0bc49-fc15-40d2-9713-188402062ea6</UniqueId>    <FSObjType>0</FSObjType>    <Created_x0020_Date>8/5/2009 9:09</Created_x0020_Date>    <Created>8/5/2009 2:09:42 PM</Created>  </ListItem>  <ListItem>    <Attachments>False</Attachments>    <LinkTitle>ASI VIDEO</LinkTitle>    <desc>ASI VIDEO </desc>    <image href="/Communities/Directorates/Logistics/Newpage/images/videoimg.png">    </image>    <more href="/Communities/Directorates/Logistics/Newpage/images/LOGISTICS ASI.wmv">more</more>    <FileRef>/Communities/Directorates/Logistics/Lists/news/4_.000</FileRef>    <FileDirRef>Communities/Directorates/Logistics/Lists/news</FileDirRef>    <FileLeafRef>4_.000</FileLeafRef>    <ServerUrl>/Communities/Directorates/Logistics/Lists/news/4_.000</ServerUrl>    <BaseName>4_</BaseName>    <ID>4</ID>    <_ModerationStatus>0</_ModerationStatus>    <_Level>1</_Level>    <owshiddenversion>4</owshiddenversion>    <UniqueId>a74a5c02-fc6b-4e33-9120-f88800018f87</UniqueId>    <FSObjType>0</FSObjType>    <Created_x0020_Date>8/18/2009 7:40</Created_x0020_Date>    <Created>8/18/2009 12:40:07 PM</Created>  </ListItem></ListItems>

xslt

<?xml version="1.0" encoding="utf-8"?><!-- DWXMLSource="news.xml" --> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"><xsl:output method="html" encoding="utf-8" doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN" doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"/><xsl:template match="/"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"/><title>Untitled Document</title><STYLE type="text/css"><!--html {   direction:;  background-attachment:fixed;   scrollbar-arrow-color: #ffffff;  scrollbar-track-color: #999999;  scrollbar-face-color: #000000;  scrollbar-highlight-color: ;  scrollbar-3dlight-color: ;  scrollbar-darkshadow-color: ;  scrollbar-shadow-color: ;}--></STYLE></head><body><table cellspacing="0px" cellpadding="1px" style="width:560px; border:0px; color:#999999;"><tr><th align='center' colspan="2" style=" background-image:url(images/posttop1.gif); background-repeat:repeat; height:30px; color: #CCCCCC; font:Arial, Helvetica, sans-serif; font-size:18px; font-weight:bold;">LOGISTICS NEWS</th></tr></table><div style="width:580px; height: 300px; overflow-x:hidden ;overflow-y:scroll;"><table cellspacing="0px" cellpadding="1px" style="width:560px;border:0px; color:#999999;"><xsl:for-each select="ListItems/ListItem"><xsl:sort select="id" order="descending"/><tr style="background-image: url(images/postmiddle1.gif); background-repeat:repeat; width:560px; height:130px;"><td width="85"><img src="{image/@href}" width="125" height="120" align="right" style="border: solid; border-color:#999999; border-width:2px; "/></td><td width="416" align="center"><div style="font:Arial, Helvetica, sans-serif; font-size:14px; font-weight:bold; color:#999999;"><u><xsl:value-of select="LinkTitle"/></u></div><div style="font:Arial, Helvetica, sans-serif; font-size:12px; font-weight:bold; color:#525757;"><xsl:value-of select="desc/div|desc"/><a><xsl:attribute name="href">       <xsl:value-of select="more/@href"/></xsl:attribute>        <xsl:value-of select="more"/>        </a></div></td></tr></xsl:for-each><tr><td colspan="2" style=" background-image:url(images/postbottom1.gif); color:#000000">.s</td></tr></table></div></body></html></xsl:template></xsl:stylesheet>

Edited by anujojha
Link to comment
Share on other sites

You have your casing wrong. You have

<xsl:sort select="id" order="descending"/>

but your XML has

<ID>1</ID>

Which means that your XSLT sort should be:

<xsl:sort select="ID" order="descending"/>

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...