XML Editor
Sign up for a WebBoard account Sign Up Keyword Search Search More Options... Options
Chat Rooms Chat Help Help News News Log in to WebBoard Log in Not Logged in
Show tree view Topic
Topic Page 1 2 3 4 5 6 7 8 9 Go to previous topicPrev TopicGo to next topicNext Topic
Postnext
Manu GuptaSubject: Remove duplicates
Author: Manu Gupta
Date: 15 Jul 2011 06:45 AM
Hi All,
I have string variable "AABBCDNNN" and I need to create string which contains only distinct values "ABCDN". I am using XSLT 1.0.

Help will be really appreciated.

Thanks

Posttop
Ivan PedruzziSubject: Remove duplicates
Author: Ivan Pedruzzi
Date: 20 Jul 2011 11:21 PM

XSLT 1.0 has weak support for string manipualtion compare to version 2.0. See if the following helps


input xml

<?xml version="1.0"?>
<root>AABBCDNNN</root>


XSLT

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template name="unique">
<xsl:param name="p" select="1"/>
<xsl:param name="s"/>
<xsl:if test="$p &lt;= string-length($s)">
<xsl:if test="substring($s, $p, 1) != substring($s, $p -1, 1)">
<xsl:value-of select="substring($s, $p, 1)"/>
</xsl:if>
<xsl:call-template name="unique">
<xsl:with-param name="p" select="$p + 1"/>
<xsl:with-param name="s" select="$s"/>
</xsl:call-template>
</xsl:if>
</xsl:template>
<xsl:template match="/">
<xsl:call-template name="unique">
<xsl:with-param name="s" select="."/>
</xsl:call-template>
</xsl:template>
</xsl:stylesheet>

 
Topic Page 1 2 3 4 5 6 7 8 9 Go to previous topicPrev TopicGo to next topicNext Topic
Download A Free Trial of Stylus Studio 6 XML Professional Edition Today! Powered by Stylus Studio, the world's leading XML IDE for XML, XSLT, XQuery, XML Schema, DTD, XPath, WSDL, XHTML, SQL/XML, and XML Mapping!  
go

Log In Options

Site Map | Privacy Policy | Terms of Use | Trademarks
Stylus Scoop XML Newsletter:
W3C Member
Stylus Studio® and DataDirect XQuery ™are from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2016 All Rights Reserved.