Tokenize and compare dates in xslt 1.0

空扰寡人 提交于 2019-12-14 04:23:54

问题


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.


回答1:


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).



来源:https://stackoverflow.com/questions/32071733/tokenize-and-compare-dates-in-xslt-1-0

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!