Deduplicating a String
I have an element with the value /123/23/22/23/123. I am able to break the string into separate components 123 23 22 23 and 123, but is there a way to remove the duplicates from this element and display them as the output shown below? I am adding both the xml and xslt that I used for it. Please give me some direction on this.
Required Output:
<resource>
<name>123</name>
</resource>
<resource>
<name>23</name>
</resource>
<resource>
<name>22</name>
</resource>
but output that I am getting is:
<resource>
<name>123</name>
</resource>
<resource>
<name>23</name>
</resource>
<resource>
<name>22</name>
</resource>
<resource>
<name>23</name>
</resource>
<resource>
<name>123</name>
</resource>
Here are the programs. Any help on this will be greatly appreciated. Thank you
********************************************
XML:
<?xml version="1.0" encoding="ISO-8859-1"?>
<ListOfItems>10/20/30/31/31
</ListOfItems>
*******************************************
*******************************************
XSLT:
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:template match="ListOfItems">
<xsl:variable name="SpaceOrCommaOrBoth" select="normalize-space(translate(text(),'/',' '))"/>
<xsl:call-template name="Chop">
<xsl:with-param name="SpaceOrCommaOrBoth" select="$SpaceOrCommaOrBoth"/>
</xsl:call-template>
</xsl:template>
<xsl:template name="Chop">
<xsl:param name="SpaceOrCommaOrBoth"/>
<xsl:choose>
<xsl:when test="contains($SpaceOrCommaOrBoth,' ')">
<xsl:call-template name="MakeItem">
<xsl:with-param name="ItemStff" select="substring-before($SpaceOrCommaOrBoth,' ')"/>
</xsl:call-template>
<xsl:call-template name="Chop">
<xsl:with-param name="SpaceOrCommaOrBoth" select="substring-after($SpaceOrCommaOrBoth,' ')"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:call-template name="MakeItem">
<xsl:with-param name="ItemStff" select="$SpaceOrCommaOrBoth"/>
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template name="MakeItem">
<xsl:param name="ItemStff"/>
<xsl:element name="resource">
<xsl:element name="name"><xsl:value-of select="$ItemStff"/></xsl:element>
</xsl:element>
</xsl:template>
</xsl:stylesheet>
*******************************************
|