XSLT 1.0 has no concept of dates (and even XSLT 2.0 only recognize dates in ISO-8601 format). So you need to do this in two steps:
- Convert your dates to a sortable string in the form of YYYMMDDhhmmss. This is further complicated by the necessity to convert 12-hour time to 24-hour format.
- Sort the resulting nodes and output the first (or last, depending on the sort order) one of these.
XSLT 1.0
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:exsl="http://exslt.org/common"
extension-element-prefixes="exsl">
<xsl:output method="xml" version="1.0" encoding="utf-8" indent="yes"/>
<xsl:template match="/day">
<!-- first pass -->
<xsl:variable name="events">
<xsl:for-each select="day-event">
<event name="{eventname}" date="{dateevent}">
<xsl:call-template name="convert-date">
<xsl:with-param name="datestring" select="dateevent"/>
</xsl:call-template>
</event>
</xsl:for-each>
</xsl:variable>
<!-- output -->
<output>
<xsl:for-each select="exsl:node-set($events)/event">
<xsl:sort select="." order="descending"/>
<xsl:if test="position()=1">
<eventname>
<xsl:value-of select="@name" />
</eventname>
<dateevent>
<xsl:value-of select="@date" />
</dateevent>
</xsl:if>
</xsl:for-each>
</output>
</xsl:template>
<xsl:template name="convert-date">
<xsl:param name="datestring"/>
<xsl:variable name="date" select="substring-before($datestring, ' ')" />
<xsl:variable name="time" select="substring-before(substring-after($datestring, ' '), ' ')" />
<xsl:variable name="M" select="substring-before($date, '/')" />
<xsl:variable name="D" select="substring-before(substring-after($date, '/'), '/')" />
<xsl:variable name="Y" select="substring-after(substring-after($date, '/'), '/')" />
<xsl:variable name="h12" select="substring-before($time, ':')"/>
<xsl:variable name="m" select="substring-before(substring-after($time,':'), ':')"/>
<xsl:variable name="s" select="substring-after(substring-after($time,':'), ':')"/>
<xsl:variable name="pm" select="contains($datestring,'PM')"/>
<xsl:variable name="h" select="$h12 mod 12 + 12*$pm"/>
<xsl:value-of select="format-number($Y, '0000')" />
<xsl:value-of select="format-number($M, '00')" />
<xsl:value-of select="format-number($D, '00')" />
<xsl:value-of select="format-number($h, '00')" />
<xsl:value-of select="format-number($m, '00')" />
<xsl:value-of select="format-number($s, '00')" />
</xsl:template>
</xsl:stylesheet>
Result
?xml version="1.0" encoding="utf-8"?>
<output>
<eventname>Test2</eventname>
<dateevent>4/29/2015 6:55:58 PM</dateevent>
</output>
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…