[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: Removing non-alphanumeric characters from attribut
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
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|