๐ Handling Multiple Stub & Payment Matching in XSLT (OIC Optimization)
๐ Problem Context
We receive:
Multiple StubRecords
Multiple PaymentRecords
Same Transaction Number across records
๐ Goal:
Correctly match multiple stubs with multiple payments
Ensure accurate mapping
Avoid 120 sec XSLT timeout
⚠️ Issue with Traditional Matching
XML
//ns25:PaymentRecord[ns25:TransactionNumber = $txn]
❌ Fetches all records
❌ Incorrect matching
❌ Slow → Timeout
✅ Optimized Steps Using xsl:key
๐ Step 1: Define Keys
XML
<xsl:key name="stubKey"
match="ns25:StubRecord"
use="concat(ns25:TransactionNumber,'|',ns25:OperatorID)"/>
<xsl:key name="payKey"
match="ns25:PaymentRecord"
use="concat(ns25:TransactionNumber,'|',normalize-space(ns25:Filler3))"/>
<xsl:key name="payKeyExact"
match="ns25:PaymentRecord"
use="concat(ns25:TransactionNumber,'|',normalize-space(ns25:Filler3),'|',ns25:PaymentAmount)"/>
๐ Step 2: Loop Through Stub Records
XML
<xsl:for-each select="$ReadSourceFile/.../ns25:StubRecord">
๐งฎ Step 3: Extract Values
XML
<xsl:variable name="txn" select="ns25:TransactionNumber"/>
<xsl:variable name="op" select="ns25:OperatorID"/>
<xsl:variable name="amt" select="ns25:PaidAmount"/>
๐ Step 4: Build Composite Keys
XML
<xsl:variable name="stubKeyVal" select="concat($txn,'|',$op)"/>
<xsl:variable name="payKeyVal" select="concat($txn,'|',$op)"/>
<xsl:variable name="payKeyExactVal" select="concat($txn,'|',$op,'|',$amt)"/>
⚡ Step 5: Fetch Using Key
XML
<xsl:variable name="sameStub" select="key('stubKey',$stubKeyVal)"/>
<xsl:variable name="payments" select="key('payKey',$payKeyVal)"/>
<xsl:variable name="paymentsExact" select="key('payKeyExact',$payKeyExactVal)"/>
๐ Step 6: Handle Multiple Stub Records
XML
<xsl:if test="count($sameStub) > 1">
๐ Ensures:
Only process when multiple stubs exist for same transaction + operator
Avoid incorrect or duplicate mapping
๐ฏ Step 7: Choose Best Payment Match
XML
<xsl:variable name="finalPayments"
select="if (exists($paymentsExact)) then $paymentsExact else $payments"/>
๐ Prefer:
Exact match (txn + operator + amount)
Else fallback
๐ Step 8: Map & Merge Data
XML
<xsl:value-of select="normalize-space(ns25:StubAccountNumber)"/>
<xsl:value-of select="oraext:create-delimited-string($finalPayments/ns25:ChequeNumber,'|')"/>
๐ค Step 9: Generate Output
๐ One output per valid stub, enriched with matched payments
๐ฏ Final One-Line Summary
๐ “Use xsl:key with composite keys to accurately match multiple stub and payment records for the same transaction, handle multi-stub scenarios using count logic, and ensure optimized performance to avoid XSLT timeout in OIC.”
Code Screenshots:


No comments:
Post a Comment