3/20/2018 - 5:32 AM

Eliminate duplicate attribute

First create a node-set and sort it alphabetically. Then interate over that node set and if the very previous node matches then we do not add it to the second node-set. Finally we output the second node-set.

<?xml version="1.0" encoding="UTF-8"?>
    exclude-result-prefixes="pa ms"
	<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>

	<xsl:template match="/">
      <xsl:apply-templates select="/LenderParam/Products/Product"/>

	<xsl:template match="/LenderParam/Products/Product">
        <xsl:apply-templates select="Product"/>

    <xsl:template match="Product">
		<xsl:variable name="parentProduct" select="@display"/>

		<!-- first get all values and sort them -->
		<xsl:variable name="f1">
			<xsl:for-each select="pa:RepaymentFrequency">
				<xsl:sort select="@value"/>
					<xsl:attribute name="value">
						<xsl:value-of select="@value"/>
		<xsl:variable name="f1ns" select="ms:node-set($f1)" />
		<!-- now filter out duplicates -->
		<xsl:variable name="f2">
			<xsl:for-each select="$f1ns/Freq">
					<!-- if the sibiling before matches then dont add it, this works because we sorted the list so all duplicates will follow one another -->
					<xsl:when test="position() != 1">
						<xsl:if test="@value != preceding-sibling::*[1]/@value">
							<xsl:value-of select="@value"/>
					<!-- the first node has no preceeding sibling so we always add it -->
						<xsl:value-of select="@value"/>
		<xsl:variable name="f2ns" select="ms:node-set($f2)" />
		<xsl:value-of select="$f2ns"/>
		<xsl:apply-templates select="Class">
			<xsl:with-param name="parentProduct" select="$parentProduct"/>

	<xsl:template match="Class">
		<xsl:param name="parentProduct"/>

		<!-- Only Render this product if it has a malid -->
		<xsl:if test="@malid">
				<xsl:value-of select="$parentProduct"/>
				<xsl:text>, </xsl:text><xsl:value-of select="@display"/><xsl:text>-------</xsl:text><xsl:value-of select="@malid"/>