如何使用最新的EventDate获取EventType?

时间:2015-06-10 20:53:59

标签: xml xslt

我有以下带有2个EventTypes的xml文档。我想显示EventType最近的EventDate

所需的输出

<EventType eventDate="05/12/2015" eventTime="7:36 AM" noticeTypeCode="SFTP">DL reinstatement request to DPS - Fail to Pay</EventType>

如何修改我的xslt代码?

我的xml文档

    <Integration xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:tsg="http://tsgweb.com" xmlns:IXML="http://tsgweb.com" xmlns:CMCodeQueryHelper="urn:CMCodeQueryHelper" PackageID="DL Notice to DVS" MessageID="67094086" xmlns="">
    <Case InternalID="161709" ID="1218" xmlns:user="http://tylertechnologies.com">
        <CaseEvent Date="05/11/2015" ID="160825556" InternalEventID="1721874614" xmlns:reslib="urn:reslib">
            <EventDate>05/11/2015</EventDate>
            <EventTime>3:42 PM</EventTime>
            <Deleted>false</Deleted>
            <EventType Word="DLSUSFTP">DL suspension request to DPS - Fail to Pay</EventType>
        </CaseEvent>
        <CaseEvent Date="05/12/2015" ID="160825565" InternalEventID="1721874622" xmlns:reslib="urn:reslib">
            <EventDate>05/12/2015</EventDate>
            <EventTime>7:36 AM</EventTime>
            <Deleted>false</Deleted>
            <EventType Word="DLREINSNON">DL reinstatement request to DPS Nonresident-Compact State</EventType>
        </CaseEvent>
    </Case>
</Integration>

我的xsl代码

<xsl:for-each select="/Integration/Case/CaseEvent[(Deleted='false') and ((EventType/@Word='DLSUSFTP') or (EventType/@Word='DLREINSNON '))]">
    <xsl:sort select="substring(EventDate,7,4)" order="descending"/>
    <xsl:sort select="substring(EventDate,1,2)" order="descending"/>
    <xsl:sort select="substring(EventDate,4,2)" order="descending"/>
    <xsl:sort select="substring-after(EventTime,' ')" order="descending"/>
    <xsl:sort select="substring-before(EventTime,':')" order="descending" data-type="number"/>
    <xsl:sort select="substring-before(substring-after(EventTime,':'),' ')" order="descending" data-type="number"/>
    <xsl:if test="position() = 1">
</xsl:for-each>

1 个答案:

答案 0 :(得分:0)

有一点需要注意的是,from flask import Flask from flask_restful import Resource, Api, reqparse app = Flask(__name__) api = Api(app) class BarAPI(Resource): def get(self): parser = reqparse.RequestParser() parser.add_argument('key1', type=str) parser.add_argument('key2', type=str) return parser.parse_args() api.add_resource(BarAPI, '/bar', endpoint='bar') if __name__ == '__main__': app.run(debug=True)

中的表达式中存在一个小错字
xsl:for-each

您在字符串中有一个虚假空间,这意味着它不会与您在XML中显示的事件类型相匹配。

无论如何,您使用(EventType/@Word='DLREINSNON ') 获得了正确的方法,所以现在您只需要添加代码来复制<xsl:if test="position() = 1">元素

EventType

但是,查看预期的输出,实际上您还希望转换输出的<xsl:if test="position() = 1"> <xsl:copy-of select="EventType"/> </xsl:if> 元素。在这种情况下,您可以在此处使用EventType

试试这个XSLT

xsl:apply-templates

请注意在创建属性值时使用Attribute Value Templates