Amith Bapu
Amith Bapu

Reputation: 3

Find max of date from different nodes in XSLT

Below is my XML Code where I have multiple date nodes. I need to find the maximum date of all these dates which are not in any specific node order.

<?xml version="1.0" encoding="UTF-8"?>
<ns1:Workers>
<ns1:Worker>
    <ns1:Summary>
        <ns1:Employee_ID>12345678</ns1:Employee_ID>
        <ns1:Name>David J Rock</ns1:Name>
    </ns1:Summary>
    <ns1:Personal>
        <ns1:Birth_Date>1965-05-03</ns1:Birth_Date>
    </ns1:Personal>
    <ns1:Status>
        <ns1:Employee_Status>Active</ns1:Employee_Status>
        <ns1:Active_Status_Date>2015-01-16</ns1:Active_Status_Date>
        <ns1:Hire_Date>2015-01-16</ns1:Hire_Date>
        <ns1:Original_Hire_Date>2012-04-16</ns1:Original_Hire_Date>
    </ns1:Status>
    <ns1:Position>
        <ns1:Effective_Date>2015-01-16</ns1:Effective_Date>
    </ns1:Position>
    <ns1:Compensation>
        <ns1:Effective_Date>2018-03-02</ns1:Effective_Date>
    </ns1:Compensation>
    <ns1:Additional_Information>
        <ns1:Location_Effective_Date>2015-01-16</ns1:Location_Effective_Date>
    </ns1:Additional_Information>
</ns1:Worker>

Upvotes: 0

Views: 213

Answers (1)

Martin Honnen
Martin Honnen

Reputation: 167696

That sample doesn't even define the namespace for the ns1 prefix it uses so you can't parse it with an XML parser but assuming you have any namespace declaration then a generic max use in XSLT 2 or 3 is <xsl:value-of select="max(//*[not(*) and . castable as xs:date]/xs:date(.))"/>: https://xsltfiddle.liberty-development.net/6qVRKwm

Upvotes: 1

Related Questions