按日期排序 xml 的问题<xsl:sort select=""/> [英] problem in sorting xml by date<xsl:sort select=""/>

查看:30
本文介绍了按日期排序 xml 的问题<xsl:sort select=""/>的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试按日期对我的 xml 进行排序,但它不能像这样使用我的 xml 和 xsl r

I am trying to sort my xml by date but its not working my xml and xsl r like this

<xsl:template match="/">
    <xsl:for-each select="news/item">
                        <xsl:sort select="date1" order="descending" />                                     

                          <xsl:value-of select="date1"/>                                

                  </xsl:for-each> 
</xsl:template>

MYXML

<news>
 <item>
<date1>January 1, 2010</date1>
 </item>
 <item>
  <date1>November 29, 2009</date1>
</news>


         Its displaying the result but not in sorted way..

推荐答案

xsl-sort 不知道"如何对日期进行排序.它将默认使用文本排序,但您可以使用 data-type 属性指定数字排序.

有几种方法可以解决这个问题 - 添加属性或更改您如何将日期输出到源 XML,因此您必须使用可以按数字排序的表示形式.

There are several approches to solve this - add an attribute or change how you output the date to the source XML, so you have to a representation you can sort numerically.

这篇关于按日期排序 xml 的问题&lt;xsl:sort select=""/&gt;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆