我有一组带有时间戳格式日期的节点,我正在使用<xsl:for-each>
进行迭代。如何获得最接近保存在$currentDate
中的当前日期的节点?
<xsl:variable name="currentDate" select="1396332574" />
<items>
<item>
<tmstmp>1374249600</tmstmp>
</item>
<item>
<tmstmp>1374249600</tmstmp>
</item>
<item>
<tmstmp>1374257700</tmstmp>
</item>
<item>
<tmstmp>1374418800</tmstmp>
</item>
<item>
<tmstmp>2777068800</tmstmp>
</item>
</items>
试试
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:strip-space elements="*"/>
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:variable name="currentDate" select="1396332574" />
<xsl:template match="/">
<xsl:for-each select="items/item">
<xsl:sort select="$currentDate - ." data-type="number" order="ascending"/>
<xsl:if test="position() = 1">
<xsl:copy-of select="."/>
</xsl:if>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
它输出:
<item>
<tmstmp>1374418800</tmstmp>
</item>