Это трудно понять.
Предполагая, что ваш ввод действительно выглядит примерно так:
XML
<DocumentAction>
<ActionType>Forward</ActionType>
<Status>Re-Submitted</Status>
<TransactionDateTime>2019-05-25T12:00:42</TransactionDateTime>
<ActionType>Submit</ActionType>
<Status>Re-Submitted</Status>
<TransactionDateTime>2019-05-23T12:00:42</TransactionDateTime>
<ActionType>Submit</ActionType>
<Status>Re-Submitted</Status>
<TransactionDateTime>2019-05-21T12:00:42</TransactionDateTime>
<ActionType>Submit</ActionType>
<Status>Submitted</Status>
<TransactionDateTime>2019-05-19T12:00:42</TransactionDateTime>
<ActionType>Submit</ActionType>
<Status>Submitted</Status>
<TransactionDateTime>2019-05-17T12:00:42</TransactionDateTime>
</DocumentAction>
вы можете использоватьследующая таблица стилей:
XSLT 2.0
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
exclude-result-prefixes="xs">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:template match="/DocumentAction">
<xsl:variable name="resubmitted" select="TransactionDateTime[preceding-sibling::ActionType[1]='Submit' and preceding-sibling::Status[1]='Re-Submitted']" as="xs:dateTime*"/>
<xsl:variable name="submitted" select="TransactionDateTime[preceding-sibling::ActionType[1]='Submit' and preceding-sibling::Status[1]='Submitted']" as="xs:dateTime*"/>
<output>
<xsl:choose>
<xsl:when test="count($resubmitted)">
<xsl:value-of select="format-dateTime(max($resubmitted),'[M01]/[D01]/[Y0001]')"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="format-dateTime(max($submitted),'[M01]/[D01]/[Y0001]')"/>
</xsl:otherwise>
</xsl:choose>
</output>
</xsl:template>
</xsl:stylesheet>
для возврата:
Результат
<?xml version="1.0" encoding="UTF-8"?>
<output>05/23/2019</output>
это последняя дата, для которой ActionType = 'Submit' AND Status = 'Re-Submitted'.
Демо : https://xsltfiddle.liberty -development.net / 3NJ38ZJ
Если вы удалите эти действия, так что ввод будет:
XML
<DocumentAction>
<ActionType>Forward</ActionType>
<Status>Re-Submitted</Status>
<TransactionDateTime>2019-05-25T12:00:42</TransactionDateTime>
<ActionType>Submit</ActionType>
<Status>Submitted</Status>
<TransactionDateTime>2019-05-19T12:00:42</TransactionDateTime>
<ActionType>Submit</ActionType>
<Status>Submitted</Status>
<TransactionDateTime>2019-05-17T12:00:42</TransactionDateTime>
</DocumentAction>
результат будет:
Результат
<?xml version="1.0" encoding="UTF-8"?>
<output>05/19/2019</output>
, которыйсамая последняя дата, для которой ActionType = 'Submit' AND Status = 'Submitted'.
Демо : https://xsltfiddle.liberty -development.net / 3NJ38ZJ / 1
Добавлено:
Ещеэлегантная версия той же идеи:
XSLT 2.0
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
exclude-result-prefixes="xs">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:template match="/DocumentAction">
<xsl:variable name="resubmitted" select="TransactionDateTime[preceding-sibling::ActionType[1]='Submit' and preceding-sibling::Status[1]='Re-Submitted']" as="xs:dateTime*"/>
<xsl:variable name="submitted" select="TransactionDateTime[preceding-sibling::ActionType[1]='Submit' and preceding-sibling::Status[1]='Submitted']" as="xs:dateTime*"/>
<xsl:variable name="latest-dateTime" select="if (count($resubmitted)) then max($resubmitted) else max($submitted)"/>
<output>
<xsl:value-of select="format-dateTime($latest-dateTime,'[M01]/[D01]/[Y0001]')"/>
</output>
</xsl:template>
</xsl:stylesheet>