I need to ignore duplicate values while iterating in ForEach loop with Custom Function. I have below examples and share xslt which am trying to do. I can't apply foreach group in xslt 2.0, as it will break existing Code Functionality. Am expecting to resolve this issue with Custom Function itself.
Custom Function:
<xsl:function name="OriginalBook.Genre">
<xsl:param name="book"/>
<xsl:for-each select="$book[price < 10]">
<xsl:element name="OriginalGenre">
<xsl:if test="book[not(preceding::genre)]">
<xsl:value-of select="current()/genre"/>
</xsl:if>
</xsl:element>
</xsl:for-each>
</xsl:function>
<xsl:template match="/">
<OriginalBook>
<xsl:copy-of select="OriginalBook.Genre(/catalog/book)"/>
</OriginalBook>
</xsl:template>
Input:
<?xml version="1.0"?>
<catalog>
<book>
<author>Gambardella, Matthew</author>
<title>XML Developer's Guide</title>
<genre>Computer</genre>
<price>9.95</price>
<publish_date>2000-10-01</publish_date>
</book>
<book>
<author>Ralls, Kim</author>
<title>XML Developer's Guide</title>
<genre>Computer</genre>
<price>5.95</price>
<publish_date>2000-12-16</publish_date>
</book>
<book>
<author>Corets, Eva</author>
<title>Maeve Ascendant</title>
<genre>Fantasy</genre>
<price>5.95</price>
<publish_date>2000-11-17</publish_date>
</book>
<book>
<author>Galos, Mike</author>
<title>Visual Studio 7: A Comprehensive Guide</title>
<genre>Computer</genre>
<price>49.95</price>
<publish_date>2001-04-16</publish_date>
</book>
</catalog>
Desired output:
<OriginalBook>
<OriginalGenre>Computer</OriginalGenre>
<OriginalGenre>Fantasy</OriginalGenre>
</OriginalBook>