Input XML is below. I need output xml with the latest date extracted from date field and update the date field with max date value.
<?xml version="1.0" encoding="UTF-8"?><rsp:response xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:rsp="rsp.com/employee/Response/v30"
xmlns:res="res.com/Member/details/v1">
<rsp:period>
<res:Period>
<rsp:date>2020-07-06T19:38:39</rsp:date>
</res:Period>
</rsp:period>
<rsp:period>
<res:Period>
<rsp:date>2020-08-07T20:38:39</rsp:date>
</res:Period>
</rsp:period>
<rsp:period>
<res:Period>
<rsp:date>2020-05-06T19:18:39</rsp:date>
</res:Period>
</rsp:period></rsp:response>
Below is the XLST being used for input xml
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:rsp="rsp.com/employee/Response/v30">
<xsl:output method="xml" indent="yes" omit-xml-declaration="yes"/>
<xsl:template match="node() | @*">
<xsl:copy>
<xsl:apply-templates select="node() | @*"/>
</xsl:copy>
</xsl:template>
<xsl:template
match="*[local-name() = 'response']/*[local-name() = 'period']/*[local-name() = 'Period']/*[local-name() = 'date']">
<xsl:copy>
<xsl:apply-templates/>
<xsl:copy-of select="*[local-name() = 'date']"/>
</xsl:copy>
</xsl:template>
<xsl:template match="/">
<xsl:for-each
select="*[local-name() = 'response']/*[local-name() = 'period']/*[local-name() = 'Period']/*[local-name() = 'date']">
<xsl:sort select="translate(., '-T:Z', '')" data-type="number"/>
<xsl:choose>
<xsl:when test="position() = last()">
<xsl:copy-of select="."/>
</xsl:when>
</xsl:choose>
</xsl:for-each>
</xsl:template></xsl:stylesheet>
Below is the output for this XSLT. It is able to extract the latest date but not able to update the latest extracted date in incoming date field values.
<rsp:date xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:rsp="rsp.com/employee/Response/v30"
xmlns:res="res.com/Member/details/v1">2020-08-07T20:38:39</rsp:date>
Below is the expected output
<?xml version="1.0" encoding="UTF-8"?><rsp:response xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:rsp="rsp.com/employee/Response/v30"
xmlns:res="res.com/Member/details/v1">
<rsp:period>
<res:Period>
<rsp:date>2020-08-07T20:38:39</rsp:date>
</res:Period>
</rsp:period>
<rsp:period>
<res:Period>
<rsp:date>2020-08-07T20:38:39</rsp:date>
</res:Period>
</rsp:period>
<rsp:period>
<res:Period>
<rsp:date>2020-08-07T20:38:39</rsp:date>
</res:Period>
</rsp:period></rsp:response>