Subject: Re: [xsl] Removing non-alphanumeric characters from attribute From: Mukul Gandhi <mukul_gandhi@xxxxxxxxx> Date: Thu, 24 Jun 2004 23:58:15 -0700 (PDT) |
Please try the XSL - <?xml version="1.0"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:variable name="str" select="'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'" /> <xsl:template match="node()"> <xsl:copy> <xsl:for-each select="@*"> <xsl:attribute name="{name()}"> <xsl:variable name="att-val" select="." /> <xsl:call-template name="stripchars"> <xsl:with-param name="x" select="substring($att-val, 1, 1)" /> <xsl:with-param name="y" select="substring(., 2, string-length($att-val))" /> </xsl:call-template> </xsl:attribute> </xsl:for-each> <xsl:apply-templates /> </xsl:copy> </xsl:template> <xsl:template name="stripchars"> <xsl:param name="x" /> <xsl:param name="y" /> <xsl:if test="contains($str, $x)"> <xsl:value-of select="$x" /> </xsl:if> <xsl:if test="string-length($y) > 0"> <xsl:call-template name="stripchars"> <xsl:with-param name="x" select="substring($y, 1, 1)" /> <xsl:with-param name="y" select="substring($y, 2, string-length($y))" /> </xsl:call-template> </xsl:if> </xsl:template> </xsl:stylesheet> for e.g. when it is applied to XML - <?xml version="1.0"?> <root> <a x="123ABC+-" /> <b y="ABC12" /> <c z="+-1" /> </root> it produces output - <?xml version="1.0"?> <root> <a x="123ABC" /> <b y="ABC12" /> <c z="1" /> </root> Regards, Mukul --- perry.ielati@xxxxxxxxxxxx wrote: > Hi all, > > I was wondering if there is any way possible of > stripping any non-alphanumeric > characters from an attribute. ie keep anything that > is A-Z/0-9 and strip all > other characters like ",*-+. etc etc? > > Thanks > -Pez __________________________________ Do you Yahoo!? Yahoo! Mail is new and improved - Check it out! http://promotions.yahoo.com/new_mail
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Removing non-alphanumeric character, perry . ielati | Thread | Re: Removing non-alphanumeric chara, Dimitre Novatchev |
Re: Removing non-alphanumeric chara, Dimitre Novatchev | Date | i18n problem while displaying using, Ranjan K. Baisak |
Month |