【孟宪会之精彩世界】DHtml精彩放送

来源:互联网 发布:网络舆论的重要性 编辑:程序博客网 时间:2024/05/20 06:25
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 728x15, 创建于 08-4-23MSDN */google_ad_slot = "3624277373";google_ad_width = 728;google_ad_height = 15;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 160x600, 创建于 08-4-23MSDN */google_ad_slot = "4367022601";google_ad_width = 160;google_ad_height = 600;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
在XSLT实现按日期排序作者:孟宪会 出自:【孟宪会之精彩世界】 发布日期:2004年2月21日 11点47分56秒

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

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

SortXML.xsl

<?xml version="1.0" encoding="gb2312"?><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"> <thead> <th width="50%">标题</th> <th width="50%">修改时间</th> </thead> <xsl:for-each select="/multistatus/response"> <xsl:sort order="descending" select="user:xmlDateTime(string(getlastmodified))" data-type="number"/> <xsl:value-of select="Title"/> <xsl:value-of select="getlastmodified"/> </xsl:for-each> </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>【<A href="http://www.66of.com" target=_blank>孟宪会之精彩世界</A>】</Title> </response> <response> <href>http://dotnet.aspx.cc/Play.aspx</href> <getlastmodified>2004-10-23 11:11:10</getlastmodified> <Title>【<A href="http://www.66of.com" target=_blank>孟宪会之精彩世界</A>】音乐频道</Title> </response> <response> <href>http://dotnet.aspx.cc/</href> <getlastmodified>2004-02-10 18:36:19</getlastmodified> <Title>【<A href="http://www.66of.com" target=_blank>孟宪会之精彩世界</A>】</Title> </response> <response> <href>http://lucky.myrice.com/</href> <getlastmodified>2004-01-14 10:51:21</getlastmodified> <Title>【<A href="http://www.66of.com" target=_blank>孟宪会之精彩世界</A>】</Title> </response> <response> <href>http://dotnet.aspx.cc/ShowList.aspx&amp;id=1</href> <getlastmodified>2003-11-2 10:52:26</getlastmodified> <Title>【<A href="http://www.66of.com" target=_blank>孟宪会之精彩世界</A>】ASP.NET</Title> </response> <response> <href>http://dotnet.aspx.cc/CoolMenu/main.htm</href> <getlastmodified>1999-02-21 22:07:43</getlastmodified> <Title>【<A href="http://www.66of.com" target=_blank>孟宪会之精彩世界</A>】<A href="http://www.66of.com" target=_blank>DHtml</A><A href="http://www.66of.com" target=_blank>精彩放送</A></Title> </response></multistatus>

查看转换结果

http://sz.luohuedu.net/xml/SortXML.xml

<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 728x15, 创建于 08-4-23MSDN */google_ad_slot = "3624277373";google_ad_width = 728;google_ad_height = 15;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 160x600, 创建于 08-4-23MSDN */google_ad_slot = "4367022601";google_ad_width = 160;google_ad_height = 600;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>