Xpath 1.0查询排序和提取最小日期值不起作用

问题描述 投票:0回答:1

我不得不在几个节点之间提取最早的日期并将其放入一个新的xml中。

基于另一个线程(我找不到对不起的url)我做了这个查询:

substring-before(string(/*[local-name()='EmployeeUDM_Response']/*[local-name()='Return']/*[local-name()='Employee']/*[local-name()='Contracts']/*[local-name()='Contract']/*[local-name()='EmployementStartDate'][not(. >= following::*[local-name()='EmployementStartDate'])][not(. >= preceding::*[local-name()='EmployementStartDate'])][1]), 'T')

XML输入

<ns0:EmployeeUDM_Response xmlns:ns0="http://Schemas/v2/EmployeeUDM">
    <ns0:Header Type="Employee" Source="Biztalk ESB" Target="EmployeeUDMToRostarCas" Date="2019-04-29T15:24:24" />
    <ns0:Return>
        <ns0:Employee>
            <ns0:ID>f416d1cd-d13f-433c-9297-7fa724b10872</ns0:ID>
            <ns0:Number>200002</ns0:Number>
            <ns0:SagaNumber></ns0:SagaNumber>
            <ns0:SocialSecurityNumber>663993258</ns0:SocialSecurityNumber>
            <ns0:SurNameFull>Streep</ns0:SurNameFull>
            <ns0:FirstName>Meryl</ns0:FirstName>
            <ns0:Gender>Vrouw</ns0:Gender>
            <ns0:DateOfBirth>1988-02-25T00:00:00.0000000+01:00</ns0:DateOfBirth>
            <ns0:Contracts>
                <ns0:Contract>
                    <ns0:ID>9cfae674-da54-418c-9d7f-2f1dfcdc64d3</ns0:ID>
                    <ns0:StartDate>2018-01-01T00:00:00.0000000+01:00</ns0:StartDate>
                    <ns0:EndDate>2019-01-01T00:00:00.0000000+01:00</ns0:EndDate>
                    <ns0:EmployementStartDate>2018-02-01T00:00:00.0000000+01:00</ns0:EmployementStartDate>
                    <ns0:EmployementEndDate>2018-03-01T00:00:00.0000000+01:00</ns0:EmployementEndDate>
                </ns0:Contract>
                <ns0:Contract>
                    <ns0:ID>a584c7d8-a5a1-45a7-9cb9-4dabe9ece851</ns0:ID>
                    <ns0:StartDate>2018-01-01T00:00:00.0000000+01:00</ns0:StartDate>
                    <ns0:EndDate>2019-01-01T00:00:00.0000000+01:00</ns0:EndDate>
                    <ns0:EmployementStartDate>2019-02-01T00:00:00.0000000+01:00</ns0:EmployementStartDate>
                    <ns0:EmployementEndDate>2019-03-01T00:00:00.0000000+01:00</ns0:EmployementEndDate>
                </ns0:Contract>
                <ns0:Contract>
                    <ns0:ID>9a1cfe04-6d4a-4a97-9104-b2633dbb6362</ns0:ID>
                    <ns0:StartDate>2018-01-01T00:00:00.0000000+01:00</ns0:StartDate>
                    <ns0:EndDate>2019-01-01T00:00:00.0000000+01:00</ns0:EndDate>
                    <ns0:EmployementStartDate>2017-02-01T00:00:00.0000000+01:00</ns0:EmployementStartDate>
                    <ns0:EmployementEndDate>2017-03-01T00:00:00.0000000+01:00</ns0:EmployementEndDate>
                </ns0:Contract>
                <ns0:Contract>
                    <ns0:ID>b7f868fe-2b93-45a4-9683-d814e3b6eb4e</ns0:ID>
                    <ns0:StartDate>2018-01-01T00:00:00.0000000+01:00</ns0:StartDate>
                    <ns0:EndDate>2019-01-01T00:00:00.0000000+01:00</ns0:EndDate>
                    <ns0:EmployementStartDate>2016-02-01T00:00:00.0000000+01:00</ns0:EmployementStartDate>
                    <ns0:EmployementEndDate>2016-03-01T00:00:00.0000000+01:00</ns0:EmployementEndDate>
                </ns0:Contract>
                <ns0:Contract>
                    <ns0:ID>4352ead7-8888-4c94-9228-dc0245ae9388</ns0:ID>
                    <ns0:StartDate>2019-01-01T00:00:00.0000000+01:00</ns0:StartDate>
                    <ns0:EndDate>2020-01-01T00:00:00.0000000+01:00</ns0:EndDate>
                    <ns0:EmployementStartDate>2019-01-01T00:00:00.0000000+01:00</ns0:EmployementStartDate>
                    <ns0:EmployementEndDate></ns0:EmployementEndDate>
                </ns0:Contract>
                <ns0:Contract>
                    <ns0:ID>8bf2208c-9f5d-4729-83d9-f10789913a61</ns0:ID>
                    <ns0:StartDate>2018-01-01T00:00:00.0000000+01:00</ns0:StartDate>
                    <ns0:EndDate>2019-01-01T00:00:00.0000000+01:00</ns0:EndDate>
                    <ns0:EmployementStartDate>2015-02-01T00:00:00.0000000+01:00</ns0:EmployementStartDate>
                    <ns0:EmployementEndDate>2015-03-01T00:00:00.0000000+01:00</ns0:EmployementEndDate>
                </ns0:Contract>
                <ns0:Contract>
                    <ns0:ID>c2d3b8e6-ccd5-4a18-b28a-f853e2bc8f0e</ns0:ID>
                    <ns0:StartDate>2018-01-01T00:00:00.0000000+01:00</ns0:StartDate>
                    <ns0:EndDate>2019-01-01T00:00:00.0000000+01:00</ns0:EndDate>
                    <ns0:EmployementStartDate>2014-02-01T00:00:00.0000000+01:00</ns0:EmployementStartDate>
                    <ns0:EmployementEndDate>2014-03-01T00:00:00.0000000+01:00</ns0:EmployementEndDate>
                </ns0:Contract>
            </ns0:Contracts>
        </ns0:Employee>
    </ns0:Return>
</ns0:EmployeeUDM_Response>

XML输出应该是:

<ns0:Employee date="2019-04-30"http://SchemasMDSRequest_Schema">
    <Number>200002</Number>
    <SurNameFull>Streep</SurNameFull>
    <FirstName>Meryl</FirstName>
    <GivenName>Meryl</GivenName>
    <EmployementStartDate>2014-02-01</EmployementStartDate>
    <EmployementEndDate>2099-01-01</EmployementEndDate>
</ns0:Employee>

但实际的XML输出是:

<ns0:Employee date="2019-04-30"http://SchemasMDSRequest_Schema">
    <Number>200002</Number>
    <SurNameFull>Streep</SurNameFull>
    <FirstName>Meryl</FirstName>
    <GivenName>Meryl</GivenName>
    <EmployementStartDate>2018-02-01</EmployementStartDate>
    <EmployementEndDate>2099-01-01</EmployementEndDate>
</ns0:Employee>

我不得不使用XPath 1.0,因为BizTalk Server 2013不支持XPath 2.0。我不知道查询有什么问题,我对XPath很新。

xml biztalk-2013 xpath-1.0
1个回答
0
投票

XPath 1.0中的<>运算符仅在数字上定义,而不是在字符串(或日期/时间)上定义。如果在字符串上使用它们,系统将尝试将字符串转换为数字,通常会导致NaN < NaN比较,这总是错误的。

为了比较日期,一个流行的XPath 1.0解决方法是去除标点符号,然后比较说20190430和20190101作为数字。

© www.soinside.com 2019 - 2024. All rights reserved.