在 xslt 1.0 中标记和比较日期 [英] Tokenize and compare dates in xslt 1.0

查看:20
本文介绍了在 xslt 1.0 中标记和比较日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 xslt1.0 中有一个变量,它包含带有分隔符的日期,例如";2015 年 8 月 11 日 11:16;2015 年 8 月 7 日 08:27;2015 年 8 月 12 日 15:14"我想标记这个变量值并获取最新日期并将其存储在变量中.有人可以帮我吗.

I have a variable in xslt1.0 which contains dates with a separator like ";Aug 11, 2015 11:16;Aug 07, 2015 08:27;Aug12, 2015 15:14" I want to tokenize this variable value and get the latest date and store it in a variable. Can someone please help me.

推荐答案

Xalan 支持 EXSLT str:tokenize() 函数,这样就可以解决这个问题.之后,您只需要按个人日期对令牌进行排序.时间组件,并抓住最后一个.

Xalan supports the EXSLT str:tokenize() function, so that will take care of that. After that, you just need to sort the tokens by the individual date & time components, and grab the last one.

<xsl:for-each select="str:tokenize($dates, ';')">
    <!-- sort by year -->
    <xsl:sort select="substring(., 9, 4)"/>
    <!-- sort by month -->
    <xsl:sort select="string-length(substring-before('JanFebMarAprMayJunJulAugSepOctNovDec', substring(., 1, 3)))" data-type="number"/>
    <!-- sort by day -->
    <xsl:sort select="substring(., 5, 2)"/>
    <!-- sort by time -->
    <xsl:sort select="substring(., 14, 4)"/>
    <xsl:if test="position()=last()">
        <xsl:value-of select="."/>
    </xsl:if>
</xsl:for-each>

请注意,如果您的日期格式不同(在您的输入中,最后一个日期在月和日之间没有空格),这将不起作用.

Note that this will not work if your dates are not all in the same format (in your input, the last date does not have a space between month and day).

这篇关于在 xslt 1.0 中标记和比较日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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