When I tried with more complex XML, I ran into a lot of problems with Martin Honnen , it doesnβt work with the XML below, so I prepared my own solution referencing Dimitre with this answer. And also I could call it a more efficient solution:
Here is the xml input:
<root> <string>aabcdbcd1abcdefghijklmanopqrstuvwxyzabcdefgh0123456789ijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz12312489796453134049446798421230156489413210315487804210313264046040489789789745648974321231564648971232344</string> <string2>oejrinsjfojofjweofj24798273492jfakjflsdjljk</string2> </root>
And here is the working XSLT code:
<xsl:template match="@* | node()"> <xsl:copy> <xsl:apply-templates select="@* | node()"/> </xsl:copy> </xsl:template> <xsl:template match="text()"> <xsl:call-template name="unique_chars"> <xsl:with-param name="input" select="."/> </xsl:call-template> </xsl:template> <xsl:template name="unique_chars"> <xsl:param name="input"/> <xsl:variable name="c"> <xsl:value-of select="substring($input, 1, 1)"/> </xsl:variable> <xsl:choose> <xsl:when test="not($input)"/> <xsl:otherwise> <xsl:choose> <xsl:when test="contains(substring($input, 2), $c)"> <xsl:call-template name="unique_chars"> <xsl:with-param name="input" select="substring($input, 2)"/> </xsl:call-template> </xsl:when> <xsl:otherwise> <xsl:value-of select="$c"/> <xsl:call-template name="unique_chars"> <xsl:with-param name="input" select="substring($input, 2)"/> </xsl:call-template> </xsl:otherwise> </xsl:choose> </xsl:otherwise> </xsl:choose> </xsl:template> </xsl:stylesheet>
source share