Search code examples
xpathbiztalkbiztalk-2013

How to fix xpath function min() "as an invalid token" in BizTalk shape?


I have an Xpath code in a BizTalk Expression shape which is return this error :

'min(/[local-name()='EmployeeUDM_Response' and namespace-uri()='http://Securitas/ESB/Schemas/v2/EmployeeUDM']/[local-name()='Return']/[local-name()='Employee']/[local-name()='Contracts']/[local-name()='Contract']/[local-name()='EmployementStartDate']/xs:dateTime(.))' has an invalid token.

I got this error several time before but it was because I had put a bad path

Xpath Code:

xpath("min(/*[local-name()='EmployeeUDM_Response' and namespace-uri()='http://Securitas/ESB/Schemas/v2/EmployeeUDM']/*[local-name()='Return']/*[local-name()='Employee']/*[local-name()='Contracts']/*[local-name()='Contract']/*[local-name()='EmployementStartDate']/xs:dateTime(.))")

XML file:

- <Employee date="date_0" rostarproject="rostarproject_1" xmlns:ns0="http://Securitas.ESB.HR.EmployeeUDMToRostar.MDSRequest_Schema">
    <UPN>UPN_0</UPN>
    <SAMAccountName>SAMAccountName_0</SAMAccountName>
    <Number>Number_0</Number>
    <SagaNumber>SagaNumber_0</SagaNumber>
    <SurNameFull>SurNameFull_0</SurNameFull>
    <FirstName>FirstName_0</FirstName>
    <GivenName>GivenName_0</GivenName>
    <Gender>Gender_0</Gender>
    <DateOfBirth>DateOfBirth_0</DateOfBirth>
    <EmailPrivate>EmailPrivate_0</EmailPrivate>
    <PhoneMobilePrivate>PhoneMobilePrivate_0</PhoneMobilePrivate>
    <PhonePrivate>PhonePrivate_0</PhonePrivate>
    <EmployementStartDate>EmployementStartDate_0</EmployementStartDate>
    <EmployementEndDate>EmployementEndDate_0</EmployementEndDate>
    - <Contracts>
        - <Contract>
            <StartDate>StartDate_0</StartDate>
            <EndDate>EndDate_0</EndDate>
            <Type>Type_0</Type>
            <DissimelarCAO>DissimelarCAO_0</DissimelarCAO>
            <PhaseID>PhaseID_0</PhaseID>
            <PB_CAO>PB_CAO_0</PB_CAO>
            <StartDate>StartDate_0</StartDate>
            <EndDate>EndDate_0</EndDate>
            <Type>Type_0</Type>
            <DissimelarCAO>DissimelarCAO_0</DissimelarCAO>
            <PhaseID>PhaseID_0</PhaseID>
            <PB_CAO>PB_CAO_0</PB_CAO>
            <StartDate>StartDate_0</StartDate>
            <EndDate>EndDate_0</EndDate>
            <Type>Type_0</Type>
            <DissimelarCAO>DissimelarCAO_0</DissimelarCAO>
            <PhaseID>PhaseID_0</PhaseID>
            <PB_CAO>PB_CAO_0</PB_CAO>
        </Contract>
    </Contracts>
    - <Functions>
        - <Function>
            <StartDate>StartDate_0</StartDate>
            <EndDate>EndDate_0</EndDate>
            <Position>Position_0</Position>
            <CostCenterCode>CostCenterCode_0</CostCenterCode>
            <CostCenter>CostCenter_0</CostCenter>
            <StartDate>StartDate_0</StartDate>
            <EndDate>EndDate_0</EndDate>
            <Position>Position_0</Position>
            <CostCenterCode>CostCenterCode_0</CostCenterCode>
            <CostCenter>CostCenter_0</CostCenter>
            <StartDate>StartDate_0</StartDate>
            <EndDate>EndDate_0</EndDate>
            <Position>Position_0</Position>
            <CostCenterCode>CostCenterCode_0</CostCenterCode>
            <CostCenter>CostCenter_0</CostCenter>
        </Function>
    </Functions>
    - <Adresses>
        - <Adress>
            <StartDate>StartDate_0</StartDate>
            <EndDate>EndDate_0</EndDate>
            <StreetNumber>StreetNumber_0</StreetNumber>
            <StreetNumberAddition>StreetNumberAddition_0</StreetNumberAddition>
            <Street>Street_0</Street>
            <ZipCode>ZipCode_0</ZipCode>
            <City>City_0</City>
            <Country>Country_0</Country>
            <Type>Type_0</Type>
            <StartDate>StartDate_0</StartDate>
            <EndDate>EndDate_0</EndDate>
            <StreetNumber>StreetNumber_0</StreetNumber>
            <StreetNumberAddition>StreetNumberAddition_0</StreetNumberAddition>
            <Street>Street_0</Street>
            <ZipCode>ZipCode_0</ZipCode>
            <City>City_0</City>
            <Country>Country_0</Country>
            <Type>Type_0</Type>
            <StartDate>StartDate_0</StartDate>
            <EndDate>EndDate_0</EndDate>
            <StreetNumber>StreetNumber_0</StreetNumber>
            <StreetNumberAddition>StreetNumberAddition_0</StreetNumberAddition>
            <Street>Street_0</Street>
            <ZipCode>ZipCode_0</ZipCode>
            <City>City_0</City>
            <Country>Country_0</Country>
            <Type>Type_0</Type>
        </Adress>
    </Adresses>
    - <Wages>
        - <Wage>
            <StartDate>StartDate_0</StartDate>
            <EndDate>EndDate_0</EndDate>
            <DissimelarZipCode>DissimelarZipCode_0</DissimelarZipCode>
            <MAXKM>MAXKM_0</MAXKM>
            <RightTravelHours>RightTravelHours_0</RightTravelHours>
            <RightTravelExpense>RightTravelExpense_0</RightTravelExpense>
            <RightAdditions>RightAdditions_0</RightAdditions>
            <StartDate>StartDate_0</StartDate>
            <EndDate>EndDate_0</EndDate>
            <DissimelarZipCode>DissimelarZipCode_0</DissimelarZipCode>
            <MAXKM>MAXKM_0</MAXKM>
            <RightTravelHours>RightTravelHours_0</RightTravelHours>
            <RightTravelExpense>RightTravelExpense_0</RightTravelExpense>
            <RightAdditions>RightAdditions_0</RightAdditions>
            <StartDate>StartDate_0</StartDate>
            <EndDate>EndDate_0</EndDate>
            <DissimelarZipCode>DissimelarZipCode_0</DissimelarZipCode>
            <MAXKM>MAXKM_0</MAXKM>
            <RightTravelHours>RightTravelHours_0</RightTravelHours>
            <RightTravelExpense>RightTravelExpense_0</RightTravelExpense>
            <RightAdditions>RightAdditions_0</RightAdditions>
        </Wage>
    </Wages>
    - <Roosters>
        - <Rooster>
            <StartDate>StartDate_0</StartDate>
            <EndDate>EndDate_0</EndDate>
            <WeekAmountOfHours>WeekAmountOfHours_0</WeekAmountOfHours>
            <StartDate>StartDate_0</StartDate>
            <EndDate>EndDate_0</EndDate>
            <WeekAmountOfHours>WeekAmountOfHours_0</WeekAmountOfHours>
            <StartDate>StartDate_0</StartDate>
            <EndDate>EndDate_0</EndDate>
            <WeekAmountOfHours>WeekAmountOfHours_0</WeekAmountOfHours>
        </Rooster>
    </Roosters>
</ns0:Employee>

I expected the output of XML with the oldest 'EmployementStartDate'


Solution

  • min() is available in XPath 2.0 but not XPath 1.0 (though perhaps it's available in Biztalk?)

    You need to change /[local-name()='x'] to /*[local-name()='x'] everywhere.

    The construct XXX/xs:date-time(.) also requires XPath 2.0.