Monday, January 6, 2025

OIC - XSLT - "Dynamic Payment Date Adjustment with XSLT: Handling Conditional Date Formatting"

Usecase:

This XSLT code dynamically adjusts the payment date (H_I_PAY_DATE) based on the comparison of the InputDay and the day part of the ValueDate from the source file. It formats the date by concatenating the year-month from ValueDate and the day from InputDay, or adjusts the date if necessary, ensuring proper formatting for payment processing.

Code used:

<xsl:choose>

<xsl:when test="number (ns28:InputDay) &lt; number (substring ($ReadSourceFile/nsmpr0:ReadResponse/ns28:Payments/ns28:FileHeader/ns28:ValueDate, 7, 2))">

<ns23:H_I_PAY_DATE xml:id="id_76">

<xsl:value-of select="concat (substring ($ReadSourceFile/nsmpr0:ReadResponse/ns28:Payments/ns28:FileHeader/ns28:ValueDate, 1, 6), fn:format-number (ns28:InputDay, '00'))"/>

</ns23:H_I_PAY_DATE>

</xsl:when>

<xsl:when test="(( number (ns28:InputDay)) &gt; ((number (substring ($ReadSourceFile/nsmpr0:ReadResponse/ns28:Payments/ns28:FileHeader/ns28:ValueDate, 7, 8)))  and ((number (substring ($ReadSourceFile/nsmpr0:ReadResponse/ns28:Payments/ns28:FileHeader/ns28:ValueDate, 5, 2)) -1) =0))">

<ns23:H_I_PAY_DATE xml:id="id_209">

<xsl:value-of select="concat ((number(substring ($ReadSourceFile/nsmpr0:ReadResponse/ns28:Payments/ns28:FileHeader/ns28:ValueDate, 1, 4)) -1), '12', fn:format-number (number (substring (ns28:InputDay, 1, 2)), '00'))"/>

</ns23:H_I_PAY_DATE>

</xsl:when>

<xsl:when test="((number (ns28:InputDay ) &gt; number (substring ($ReadSourceFile/nsmpre:ReadResponse/ns28:Payments/ns28:FileHeader/ns28:ValueDate, 7, 8 ) )) and ((number (substring ($ReadSourceFile/nsmpre: ReadResponse/ns28: Payments/ns28: FileHeader/ns28: ValueDate, 5, 2)) - 1) != 0))">

<ns23:H_T_PAY_DATE xml:id="id_76">

<xsl:value-of xml:id="id_215" select="concat (substring ($ReadSourceFile/nsmpro: ReadResponse/ns28: Payments/ns28: FileHeader/ns28:ValueDate, 1, 4), fn: format-number ((number (substring ($ReadSourceFile/nsmpre: ReadResponse/ns28: Payments/ns28: FileHeader/ns28:ValueDate, 5, 2)) - 1), &quot;00&quot;), fn: format-number (ns28: Input Day, &quot;00&quot;) )"/>

</ns23:H_T_PAY_DATE>

</xsl:when>

<xsl:otherwise>

<ns23:H_I_PAY_DATE xml:id="id_210">

<xsl:value-of select="$ReadSourceFile/nsmpr0:ReadResponse/ns28:Payments/ns28:FileHeader/ns28:ValueDate"/>

</ns23:H_I_PAY_DATE>

</xsl:otherwise>

</xsl:choose>

Screenshot:



No comments:

Post a Comment

Featured Post

OIC - difference between SOAP and REST

Difference between SOAP and REST: SOAP (Simple Object Access Protocol) Protocol : A strict protocol for message exchange with built-in stand...