使用 xslt 对 XML 中的日期进行排序 [英] sorting dates in XML using xslt
本文介绍了使用 xslt 对 XML 中的日期进行排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想使用 xslt 对 xml 中的日期进行排序,并且我的日期元素在 xsd 中使用数据类型进行验证,因为下面的日期是我的 xml 和 xsl
I want to sort the dates in xml using xslt and my date element is validated in xsd with datatype as date below is my xml and xsl
XML
<Trade xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Symbol xsi:type="TradedSymbol" Type="Swap">
<Economic xsi:type="EconomicLeg">
<Leg xsi:type="IRLegGeneratedFixed">
<Schedule xsi:type="ScheduleGeneratorFixed">
<Date>2014-06-17</Date>
</Schedule>
</Leg>
</Economic>
</Symbol>
<Symbol xsi:type="TradedSymbol" Type="Swap">
<Economic xsi:type="EconomicDetailIRLeg">
<Leg xsi:type="IRLegFloat">
<Schedule xsi:type="ScheduleGeneratorFloat">
<Date>2018-06-17</Date>
</Schedule>
</Leg>
</Economic>
</Symbol>
<Symbol xsi:type="TradedSymbol" Type="Floor">
<Economic xsi:type="EconomicDetailIRLeg">
<Leg xsi:type="IRLegFloat">
<Schedule xsi:type="ScheduleGeneratorFloat">
<Date>2000-06-17</Date>
</Schedule>
</Leg>
</Economic>
</Symbol>
</Trade>
XSD
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template name="fiExoticStructuredDeal">
<fixedIncomeExoticDeal>
<frontOfficeDealDescription>Empty decription</frontOfficeDealDescription>
<component>
<frontOfficeComponentType>
<optionDetails>
<optionStyle>European</optionStyle>
<optionDates>
<adjustedDate>
<xsl:for-each select="/Trade/Symbol/Economic/Leg/Schedule">
<xsl:sort select="concat(substring-before(Date,'-'), substring-before(substring-after(Date,'- '),'-'),substring-after(substring-after(Date,'-'),'-'))" order="ascending"/>
<xsl:choose>
<xsl:when test="position() = last()">
<xsl:value-of select="Date"/>
</xsl:when>
</xsl:choose>
</xsl:for-each>
</adjustedDate>
</optionDates>
</optionDetails>
</frontOfficeComponentType>
</component>
</fixedIncomeExoticDeal>
</xsl:template>
</xsl:stylesheet>
我无法使用 xslt 对日期进行排序.它总是为我提供 Schedule 元素中的最后一个日期.如果有人让我知道我是否遗漏了什么,那就太好了.
I am not able sort the Date using xslt.It always gives me the last date in Schedule element. It will be great if someone let me know if i am missing something.
推荐答案
使用
<xsl:sort select="Date" order="ascending"/>
这篇关于使用 xslt 对 XML 中的日期进行排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文