以文本方式查看主题

-  中文XML论坛 - 专业的XML技术讨论区  (http://bbs.xml.org.cn/index.asp)
--  『 XSL/XSLT/XSL-FO/CSS 』  (http://bbs.xml.org.cn/list.asp?boardid=8)
----  数据倒序排列。。。。[求助]  (http://bbs.xml.org.cn/dispbbs.asp?boardid=8&rootid=&id=11027)


--  作者:jeremychin
--  发布时间:10/16/2004 5:09:00 PM

--  数据倒序排列。。。。[求助]
XML:
<?xml version="1.0" encoding="utf-8" ?>
 <guestbook>
  <item>
   <id>1</id>
   <username>李小飞</username>
   <gender>1</gender>
   <email>j@eyou.com</email>
   <qq>465232</qq>
   <homepage>http://bbs.72g.com</homepage>
   <content>测试</content>
   <posttime>2004-6-30</posttime>
   <reply>fdsafdsadfsa</reply>
  </item>
  </guestbook>

XSL:
<?xml version="1.0" encoding="utf-8" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:template match="/guestbook">
 
      <xsl:apply-templates select="item" />
     
  </xsl:template>
  
  <xsl:template match="item">
    <table width= "320" border="1">              
      <tr>
        <td width = "120">
          编号:<br />
        </td>
        <td width = "200">
          <xsl:value-of select="id" /><br />
        </td>
      </tr>
    </table>
  </xsl:template>
   
</xsl:stylesheet>


我要做一个留言本本,请问兄弟们我应该怎样在XSL中实现按发表时间降序排列

先谢了。。。。


--  作者:chirac
--  发布时间:10/17/2004 11:55:00 AM

--  
-----------xml------------

<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="sort.xslt"?>
<!-- edited with XMLSPY v2004 rel. 2 U (http://www.xmlspy.com) by XML (XML) -->
<guestbook xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="C:\Documents and Settings\dave1\桌面\schema\sort\sort.xsd">
 <item>
  <id>1</id>
  <username>小李飞刀</username>
  <gender>1</gender>
  <email>j@eyou.com</email>
  <qq>456223</qq>
  <homepage>http://bbs.72.com</homepage>
  <content>测试</content>
  <posttime>2004-06-30</posttime>
  <reply>测试啥啊?</reply>
 </item>
 <item>
  <id>4</id>
  <username>步惊云</username>
  <gender>5</gender>
  <email>bu@eyou.com</email>
  <qq>4552589</qq>
  <homepage>http://bbs.bu.com</homepage>
  <content>风云~</content>
  <posttime>2004-06-28</posttime>
  <reply>我最喜欢看的一本书的主角拉</reply>
 </item>
 <item>
  <id>3</id>
  <username>无情</username>
  <gender>2</gender>
  <email>t@163.com</email>
  <qq>458712</qq>
  <homepage>http://bbs.t.com</homepage>
  <content>四大名捕</content>
  <posttime>2004-07-02</posttime>
  <reply>忘记这是啥书的人物了</reply>
 </item>
</guestbook>


--------------xslt------------------

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
 <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
 <xsl:template match="/">
  <table border="1" align="center">
   <xsl:for-each select="guestbook/item">
    <xsl:sort select="posttime" order="descending"/>
    <tr>
     <td width="80">编号:</td>
     <td width="100">
      <xsl:value-of select="id"/>
     </td>
     <td width="80">发表人:</td>
     <td width="100">
      <xsl:value-of select="username"/>
     </td>
     <td width="80">发表日期:</td>
     <td width="100">
      <xsl:value-of select="posttime"/>
     </td>
    </tr>
   </xsl:for-each>
  </table>
 </xsl:template>
</xsl:stylesheet>

--------------------------------------------------------------------------
其中xsl:sort 中的  order  的 descending  表示按降序排列,如果用 ascending  则是升序排列


--  作者:chirac
--  发布时间:10/17/2004 12:33:00 PM

--  
上面是用xsl:for-each的方法,如果用xsl:apply-templates,则使用这个:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
 <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
 <xsl:template match="guestbook">
  <xsl:apply-templates select="item">
  <xsl:sort select="posttime" order="ascending"></xsl:sort></xsl:apply-templates>
 </xsl:template>
 
 <xsl:template match="item">
  <table border="1" align="center">
   <xsl:for-each select=".">

    <tr>
     <td width="50">编号:</td>
     <td width="50">
      <xsl:value-of select="id"/>
     </td>
     <td width="80">发表人:</td>
     <td width="100">
      <xsl:value-of select="username"/>
     </td>
     <td width="80">发表日期:</td>
     <td width="100"><xsl:value-of select="posttime"></xsl:value-of></td>
    </tr>
   </xsl:for-each>
  </table>
 </xsl:template>
</xsl:stylesheet>


--  作者:jeremychin
--  发布时间:10/18/2004 9:29:00 AM

--  
谢了,真够意思
W 3 C h i n a ( since 2003 ) 旗 下 站 点
苏ICP备05006046号《全国人大常委会关于维护互联网安全的决定》《计算机信息网络国际联网安全保护管理办法》
6,578.125ms