Hi!
Please try this XSL - The translate can include other characters you want to
eliminate.
----CODE START ----
<?xml version="1.0" encoding="utf-8" ?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:strip-space elements="*"/>
<xsl:template match="root">
<root>
<xsl:for-each select="node()">
<xsl:copy>
<xsl:value-of select="translate(@*,'+-','')"/>
</xsl:copy>
</xsl:for-each>
</root>
</xsl:template>
</xsl:stylesheet>
---- CODE ENDS ---
-----Original Message-----
From: Mukul Gandhi [mailto:mukul_gandhi(_at_)yahoo(_dot_)com]
Sent: Friday, June 25, 2004 2:58 AM
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: Re: [xsl] Removing non-alphanumeric characters from attribute
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(_dot_)ielati(_at_)iinet(_dot_)net(_dot_)au 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
--+------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--+--