新书推介:《语义网技术体系》
作者:瞿裕忠,胡伟,程龚
   XML论坛     W3CHINA.ORG讨论区     计算机科学论坛     SOAChina论坛     Blog     开放翻译计划     新浪微博  
 
  • 首页
  • 登录
  • 注册
  • 软件下载
  • 资料下载
  • 核心成员
  • 帮助
  •   Add to Google

    >> XML编辑器,XML解析器,XML开发环境
    [返回] 中文XML论坛 - 专业的XML技术讨论区XML.ORG.CN讨论区 - XML技术『 XML工具及XML开发环境 』 → [转帖]在XSLT实现按日期排序 查看新帖用户列表

      发表一个新主题  发表一个新投票  回复主题  (订阅本版) 您是本帖的第 3240 个阅读者浏览上一篇主题  刷新本主题   树形显示贴子 浏览下一篇主题
     * 贴子主题: [转帖]在XSLT实现按日期排序 举报  打印  推荐  IE收藏夹 
       本主题类别:     
     minicooper8 帅哥哟,离线,有人找我吗?
      
      
      等级:大一新生
      文章:6
      积分:79
      门派:XML.ORG.CN
      注册:2006/1/18

    姓名:(无权查看)
    城市:(无权查看)
    院校:(无权查看)
    给minicooper8发送一个短消息 把minicooper8加入好友 查看minicooper8的个人资料 搜索minicooper8在『 XML工具及XML开发环境 』的所有贴子 引用回复这个贴子 回复这个贴子 查看minicooper8的博客楼主
    发贴心情 [转帖]在XSLT实现按日期排序

    我们在使用XSLT进行XML转换的时候,经常遇到按XML日期类型的数据进行排序的情况,按照默认的排序规则,很难实现正确的排序效果。虽然最新的MsXML3 SP4提供了3种数据类型的排序方式:

    <xsl:sort
        select = string-expression
        data-type = { "text" | "number Qname }
        order = { "ascending "descending
      />
    但好像仍不能满足我们的需要,下面我们就介绍日期类型数据的排序方法。我们的排序方法是基于下面语句的返回值为true的理论的:
                  <script language="JavaScript">
        alert(Date.parse("2004/08/09")==Date.parse("2004/8/9"))
                  </script>
                  
    好了,下面就是我们的xsl文件:
    SortXML.xsl

                  <?xml version="1.0" encoding="utf-8"?>
                  <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:user="http://dotnet.aspx.cc/"
    exclude-result-prefixes="msxsl user"> <msxsl:script language="JavaScript" implements-prefix="user"> function xmlDateTime(nodelist) { return Date.parse(nodelist.replace(/-/g,"/")); } </msxsl:script> <xsl:output omit-xml-declaration="yes"/> <xsl:template match="/"> <xsl:call-template name="ItemList"/> </xsl:template> <xsl:template name="ItemList">
        <table bgcolor="snow" border="1" cellpadding="5" cellspacing="2" borderColor="darkorange" style="font-size:9pt">
          <thead>
            <tr bgcolor="">
              <th width="50%">标题</th>
              <th width="50%">修改时间</th>
            </tr>
          </thead>
          <tbody>
            <xsl:for-each select="/multistatus/response"> <xsl:sort order="descending" select="user:xmlDateTime(string(getlastmodified))" data-type="number"/>
            <tr>
              <td><a href="{href}" target="_blank"> <xsl:value-of select="Title"/> </a> </td>
              <td><xsl:value-of select="getlastmodified"/> </td>
            </tr>
            </xsl:for-each>
          </tbody>
        </table>
        </xsl:template> </xsl:stylesheet>
    SortXML.xml

                  <?xml version="1.0" encoding="GB2312"?>
                  <?xml-stylesheet type="text/xsl" href="SortXML.xsl"?>
                  <multistatus> <response> <href>http://sz.luohuedu.net/xml/</href> <getlastmodified>2004-8-14 10:51:44</getlastmodified>
                  <Title>【孟宪会之精彩世界】</Title>
                  </response> <response> <href>http://dotnet.aspx.cc/Play.aspx</href> <getlastmodified>2004-10-23 11:11:10</getlastmodified>
                  <Title>【孟宪会之精彩世界】音乐频道</Title>
                  </response> <response> <href>http://dotnet.aspx.cc/</href> <getlastmodified>2004-02-10 18:36:19</getlastmodified>
                  <Title>【孟宪会之精彩世界】</Title>
                  </response> <response> <href>http://lucky.myrice.com/</href> <getlastmodified>2004-01-14 10:51:21</getlastmodified>
                  <Title>【孟宪会之精彩世界】</Title>
                  </response> <response> <href>http://dotnet.aspx.cc/ShowList.aspx&amp;id=1</href> <getlastmodified>2003-11-2 10:52:26</getlastmodified>
                  <Title>【孟宪会之精彩世界】ASP.NET</Title>
                  </response> <response> <href>http://dotnet.aspx.cc/CoolMenu/main.htm</href> <getlastmodified>1999-02-21 22:07:43</getlastmodified>
                  <Title>【孟宪会之精彩世界】DHtml精彩放送</Title>
                  </response> </multistatus>
    查看转换结果

    http://sz.luohuedu.net/xml/SortXML.xml
    {Post=0}{/Post}


       收藏   分享  
    顶(0)
      




    点击查看用户来源及管理<br>发贴IP:*.*.*.* 2006/2/20 18:57:00
     
     GoogleAdSense
      
      
      等级:大一新生
      文章:1
      积分:50
      门派:无门无派
      院校:未填写
      注册:2007-01-01
    给Google AdSense发送一个短消息 把Google AdSense加入好友 查看Google AdSense的个人资料 搜索Google AdSense在『 XML工具及XML开发环境 』的所有贴子 访问Google AdSense的主页 引用回复这个贴子 回复这个贴子 查看Google AdSense的博客广告
    2024/5/21 14:34:54

    本主题贴数1,分页: [1]

    管理选项修改tag | 锁定 | 解锁 | 提升 | 删除 | 移动 | 固顶 | 总固顶 | 奖励 | 惩罚 | 发布公告
    W3C Contributing Supporter! W 3 C h i n a ( since 2003 ) 旗 下 站 点
    苏ICP备05006046号《全国人大常委会关于维护互联网安全的决定》《计算机信息网络国际联网安全保护管理办法》
    3,355.469ms