Skip to content Skip to sidebar Skip to footer

Adding Xml Tags Dynamically And Should Not Allow Duplicates Based On Count Of Particular Tags In Xml Using Xslt

I have challenge to add xml tags dynamically based on count of one xml tag and also should not allow duplicates (I am using XSLT 1.0). For ex: I have 3 Creditor records in 'Credito

Solution 1:

Use Muenchian grouping to get only distinct creditors:

XSLT 1.0

<xsl:stylesheetversion="1.0"xmlns:xsl="http://www.w3.org/1999/XSL/Transform"><xsl:outputmethod="xml"version="1.0"encoding="UTF-8"indent="yes"/><xsl:strip-spaceelements="*"/><xsl:keyname="creditor"match="Creditor"use="Contact/AddressBookUID" /><!-- identity transform --><xsl:templatematch="@*|node()"><xsl:copy><xsl:apply-templatesselect="@*|node()"/></xsl:copy></xsl:template><xsl:templatematch="PolicyContactRoles"><xsl:copy><xsl:for-eachselect="//Creditor[count(. | key('creditor', Contact/AddressBookUID)[1]) = 1]"><Entry><AccountContactRole><Subtype>Creditor_De</Subtype><AccountContact><Contact><xsl:copy-ofselect="Contact/AddressBookUID"/></Contact></AccountContact></AccountContactRole><Subtype>PolicyCreditor_De</Subtype></Entry></xsl:for-each></xsl:copy></xsl:template></xsl:stylesheet>

Post a Comment for "Adding Xml Tags Dynamically And Should Not Allow Duplicates Based On Count Of Particular Tags In Xml Using Xslt"