2014-03-19 91 views
0

需要得到最接近的日期到日期的一般性列表,當前日期顯示在標籤CURRENT_DATE得到最早的日期

XSLT 1.0

<current_date>04.04.2014 13:00:00</current_date> 
<property_value id="8"> 
    <property_id>96</property_id> 
    <entity_id>237</entity_id> 
    <property_dir_id>0</property_dir_id> 
    <tag_name>event_date</tag_name> 
    <value>19.04.2014 18:00:00</value> 
</property_value> 
<property_value id="9"> 
    <property_id>96</property_id> 
    <entity_id>237</entity_id> 
    <property_dir_id>0</property_dir_id> 
    <tag_name>event_date</tag_name> 
    <value>05.05.2014 22:00:00</value> 
</property_value> 
<property_value id="10"> 
    <property_id>96</property_id> 
    <entity_id>237</entity_id> 
    <property_dir_id>0</property_dir_id> 
    <tag_name>event_date</tag_name> 
    <value>07.06.2014 17:00:00</value> 
</property_value> 

回答

1

我不知道是什麼你的意思是「最早」和「最接近」。但是,您可以使用以下技術的日期進行排序:

<xsl:variable name="sortedDateCsvList"> 
    <xsl:for-each select="property_value/value | current_date"> 
    <xsl:sort select="substring(.,7,4)"/><!-- year --> 
    <xsl:sort select="substring(.,4,2)"/><!-- month --> 
    <xsl:sort select="substring(.,1,2)"/><!-- day --> 
    <xsl:sort select="substring(.,12)"/><!-- time --> 
    <xsl:value-of select="concat(., ',')"/> 
    </xsl:for-each> 
</xsl:variable> 

然後,您可以使用變量做幾件事情:

  • 提取的最早日期:

    substring-before($sortedDateCsvList, ',')

  • 提取current_date後的最近日期:

    substring-before(substring-after($sortedDateCsvList, current_date), ',')

或者,如果你的屬性order="descending"添加到所有<xsl:sort>元素,你可以得到最年輕的日期和current_date之前最接近的日期。