[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: Removing non-alphanumeric characters from attribut

Subject: RE: Removing non-alphanumeric characters from attribute
From: vsubramanian@xxxxxxxxxx
Date: Fri, 25 Jun 2004 09:20:12 -0400
non alphanumeric
Sorry i just realized that piece of code wont work.

Thanks,
Vidya

-----Original Message-----
From: Mukul Gandhi [mailto:mukul_gandhi@xxxxxxxxx]
Sent: Friday, June 25, 2004 2:58 AM
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: Re:  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.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

--+------------------------------------------------------------------
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@xxxxxxxxxxxxxxxxxxxxxx>
--+--

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.