如何使用xslt从不同的xml日期节点中查找最小日期 [英] How to find minimum date from different xml date nodes using xslt
问题描述
Hi Team,
我使用xml和xslt创建了html文件。
我需要使用xslt的最小日期。在这里我的任务是我有一个不同节点的xml文件,如flightList,HotelList,CarList,....我需要从所有节点(flightList,HotelList,CarList)获得最低日期。
我创建了如下所述的应用程序。
我的XML文件写得像这样:
-------------------- --------
< TRSummary >
< FlightList >
< TravelDate > 28/04/2014 < / TravelDate >
< / FlightList >
< FlightList >
< TravelDate > 24/04/2012 < / TravelDate >
< / FlightList >
< FlightList >
< TravelDate > 30/04/2013 < / TravelDate >
< / FlightList >
< HotelsList >
< CheckInDate > 29/04/2015 < / CheckInDate >
< / HotelsList >
< HotelsList >
< CheckInDate > 22/04/2015 < / CheckInDate >
< / HotelsList >
< HotelsList >
< CheckInDate > 31/05/2016 < ; / CheckInDate >
< / HotelsList >
< CarList >
< CarFromDate > 29/04/2015 < / CarFromDate >
< / CarList >
< CarList >
< CarFromDate > 29/04/2011 < / CarFromDate >
< < span class =code-leadattribute> / CarList >
< CarList >
< CarFromDate > 23/04 / 2015 < / CarFromDate >
< / CarList >
< / TRSummary >
我的xml文档写成:
-----------------------------
< xsl:stylesheet 版本 = 1.0 xmlns:xsl = http://www.w3.org/1999/XSL/转换 xmlns:msxsl = urn:schemas-microsoft-com:xslt >
< xsl:output 方法 = xml 缩进 = 是 / >
<! - < xsl:template match =TRSummary> - >
<! - 航班TravelDate最短日期 - >
< xsl:variable name = Flight >
< xsl:for-each 选择 = TRSummary / FlightList >
< < span class =code-leadattribute> xsl:sort 选择 = number(substring(TravelDate,7,4)) 订单 = 升序 / >
< xsl:sort select = number(substring(TravelDate,3,2)) 订单 = 升序 / >
< xsl:sort 选择 = number(substring(TravelDate,1,2)) order = 升序 / < span class =code-keyword>>
< xsl:if test = position()= 1 >
< xsl:value-of select = TravelDate / >
< / xsl:if >
< / xsl:for-each >
< / xsl:variable >
<! - 酒店CheckInDate最短日期 - >
< xsl:variable name = 酒店 &g t;
< xsl:for-each 选择 = TRSummary / HotelsList >
< xsl:sort 选择 = number(substring(CheckInDate,7,4)) order = 升序 / >
< xsl:sort select = number(substring(CheckInDate,3,2)) 订单 = 升序 / >
< xsl:sort select = number(substring(CheckInDate,1,2)) 订单 = 升序 / >
< x sl:if test = position()= 1 >
< xsl:value-of 选择 = CheckInDate / >
< / xsl:if >
< / xsl:for-each >
< < span class =code-leadattribute> / xsl:variable >
<! - Car CarFromDate最短日期 - >
< < span class =code-leadattribute> xsl:variable name = Car >
< xsl:for-each 选择 = TRSummary / CarList >
< xsl:sort 选择 = number(substring(CarFromDate,7,4)) 订单 = 升序 / >
< xsl:sort 选择 = number(substring(CarFromDate,3,2)) 订单 = 升序 / >
< xsl:sort 选择 = number(substring(CarFromDate,1, 2)) order = 升序 / >
< xsl:if test = position()= 1 >
< xsl:value-of 选择 = CarFromDate / >
< / xsl :if >
< / xsl:for-each >
< / xsl:variable >
< xsl:variable name = arrays >
< 项目 >
< xsl:value-of < span class =code-attribute>选择 = $ Car / >
< / Item >
< 项目 >
< xsl:value-of 选择 < span class =code-keyword> = $ Hotel / >
< / Item >
< 项目 >
< ; xsl:value-of select = $ Flight / >
< / Item >
< / xsl:variable >
< xsl:param 名称 = array 选择 = msxsl:node -set($ arrays) / >
< xsl:template 匹配 = / >
< xsl:for-each 选择 = TRSummary >
< xsl:value-of select = $ array / Item / >
< / xsl:for-each >
< / xsl :template >
< / xsl:stylesheet >
上面的代码输出结果:
---------------------------- -------
24/04/2012 22/04/2015 29/04/2011
我需要这样的输出:
---------------
29 / 04/2011
如何获得最短约会。
请尽快指导我。
谢谢和问候,
Ramu。
Car / >
< / Item >
< 项目 >
< xsl:value-of 选择 =
酒店 / >
< / Item >
< 商品 >
< xsl:value-of select =
Flight / >
< / Item < span class =code-keyword>>
< / xsl:variable >
< xsl :param n ame = array 选择 = msxsl:node-set(
Hi Team,
I created the html file using xml and xslt.
I need minimum date using xslt. here my task is i have one xml file with different nodes like flightList,HotelList,CarList,.... I need to get the lowest date from all nodes(flightList,HotelList,CarList).
I have created application as mentioned below.
My XML File written like this:
----------------------------
<TRSummary>
<FlightList>
<TravelDate>28/04/2014</TravelDate>
</FlightList>
<FlightList>
<TravelDate>24/04/2012</TravelDate>
</FlightList>
<FlightList>
<TravelDate>30/04/2013</TravelDate>
</FlightList>
<HotelsList>
<CheckInDate>29/04/2015</CheckInDate>
</HotelsList>
<HotelsList>
<CheckInDate>22/04/2015</CheckInDate>
</HotelsList>
<HotelsList>
<CheckInDate>31/05/2016</CheckInDate>
</HotelsList>
<CarList>
<CarFromDate>29/04/2015</CarFromDate>
</CarList>
<CarList>
<CarFromDate>29/04/2011</CarFromDate>
</CarList>
<CarList>
<CarFromDate>23/04/2015</CarFromDate>
</CarList>
</TRSummary>
My xml document written like this:
-----------------------------
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt">
<xsl:output method="xml" indent="yes"/>
<!--<xsl:template match="TRSummary">-->
<!--Flight TravelDate Minimum date-->
<xsl:variable name="Flight">
<xsl:for-each select="TRSummary/FlightList">
<xsl:sort select="number(substring(TravelDate, 7, 4))" order="ascending"/>
<xsl:sort select="number(substring(TravelDate, 3, 2))" order="ascending"/>
<xsl:sort select="number(substring(TravelDate, 1, 2))" order="ascending"/>
<xsl:if test="position() = 1">
<xsl:value-of select="TravelDate"/>
</xsl:if>
</xsl:for-each>
</xsl:variable>
<!--Hotel CheckInDate Minimum date-->
<xsl:variable name="Hotel">
<xsl:for-each select="TRSummary/HotelsList">
<xsl:sort select="number(substring(CheckInDate, 7, 4))" order="ascending"/>
<xsl:sort select="number(substring(CheckInDate, 3, 2))" order="ascending"/>
<xsl:sort select="number(substring(CheckInDate, 1, 2))" order="ascending"/>
<xsl:if test="position() = 1">
<xsl:value-of select="CheckInDate"/>
</xsl:if>
</xsl:for-each>
</xsl:variable>
<!--Car CarFromDate Minimum date-->
<xsl:variable name="Car">
<xsl:for-each select="TRSummary/CarList">
<xsl:sort select="number(substring(CarFromDate, 7, 4))" order="ascending"/>
<xsl:sort select="number(substring(CarFromDate, 3, 2))" order="ascending"/>
<xsl:sort select="number(substring(CarFromDate, 1, 2))" order="ascending"/>
<xsl:if test="position() = 1">
<xsl:value-of select="CarFromDate"/>
</xsl:if>
</xsl:for-each>
</xsl:variable>
<xsl:variable name="arrays" >
<Item>
<xsl:value-of select="$Car"/>
</Item>
<Item>
<xsl:value-of select="$Hotel"/>
</Item>
<Item>
<xsl:value-of select="$Flight"/>
</Item>
</xsl:variable>
<xsl:param name="array" select="msxsl:node-set($arrays)"/>
<xsl:template match="/">
<xsl:for-each select="TRSummary">
<xsl:value-of select="$array/Item"/>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
The above code am getting output :
-----------------------------------
24/04/2012 22/04/2015 29/04/2011
I need output like this:
---------------
29/04/2011
How to get minimum date.
plz guide me ASAP.
Thanks&Regards,
Ramu.
Car"/> </Item> <Item> <xsl:value-of select="
Hotel"/> </Item> <Item> <xsl:value-of select="
Flight"/> </Item> </xsl:variable> <xsl:param name="array" select="msxsl:node-set(
这篇关于如何使用xslt从不同的xml日期节点中查找最小日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!