Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
| Search | Today's Posts | Mark Forums Read
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 28th, 2009, 12:51 AM
Registered User
 
Join Date: Jul 2009
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default REMOVE leading zero and alpha characters in string in XSL...

hi

i have a code in C language

Basically i want to remove leading zero and alphabets from string


example

000C77499 should become 7749
000wert499 should become 499
00erty100 should become 100



I want to do it in XSL . PLEASE HELP


In the below CODE above objective is already achieved in C language

CString Buff = "000C77499";
Buff.MakeUpper();
int len = Buff.GetLength();
int index = 0;
for(int len1 = Buff.GetLength(); len1>0;len1--)
if(0 != isdigit(Buff.GetAt(len1-1)))
{
index++;
continue;
}
else
{
break;
}
Buff = Buff.Mid(len-index,len);


PLEASE HELP

Last edited by san_yacha; July 28th, 2009 at 12:54 AM..
 
Old July 28th, 2009, 03:16 AM
joefawcett's Avatar
Wrox Author
Points: 9,763, Level: 42
Points: 9,763, Level: 42 Points: 9,763, Level: 42 Points: 9,763, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Exeter, , United Kingdom.
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

You posted in the XSLT forum, do you want an XSLT solution or something in C?
__________________
Joe
http://joe.fawcett.name/
 
Old July 28th, 2009, 03:19 AM
Friend of Wrox
Points: 1,306, Level: 14
Points: 1,306, Level: 14 Points: 1,306, Level: 14 Points: 1,306, Level: 14
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2008
Location: Pondicherry, India
Posts: 291
Thanks: 9
Thanked 29 Times in 29 Posts
Thumbs up

With XSLT 2.0, try the below:

Sample input xml:

<root>
<test>000c46456546</test>
<test>00ax46456546</test>
<test>0cc46456546</test>
</root>

xslt code for the above:

Code:
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:output method="xml" indent="yes"></xsl:output>

<xsl:template match="test">
<xsl:value-of select=" replace(.,'([0-9]+)([a-z]+)([0-9]+)','$3')"/>
</xsl:template>
</xsl:stylesheet>


Output:

46456546
46456546
46456546

__________________
Rummy
 
Old July 28th, 2009, 04:06 AM
mhkay's Avatar
Wrox Author
Points: 18,487, Level: 59
Points: 18,487, Level: 59 Points: 18,487, Level: 59 Points: 18,487, Level: 59
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

You need to make it clear whether you need an XSLT 1.0 or 2.0 solution.

In 2.0 you can do it using regular expressions:

replace($in, '.*?([\d]+$)', '$1')

In 1.0 you need a recursive template along the lines:

Code:
<xsl:template name="strip">
  <xsl:param name="in"/>
  <xsl:when test="translate($in, '0123456789', '')">
    <xsl:call-template name="strip">
       <xsl:with-param name="in" select="substring($in, 2)"/>
    </xsl:call-template>
  </xsl:when>
  <xsl:otherwise>
    <xsl:value-of select="$in"/>
  </xsl:otherwise>
</xsl:template>
(The translate() call removes all digits and returns true if the result is non-zero-length, that is, if the string contained a non-digit).
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference




Similar Threads
Thread Thread Starter Forum Replies Last Post
checking for alpha in a string abbylee26 Javascript How-To 2 April 12th, 2011 06:44 PM
How to remove remove elements deep using xsl Prabeen XSLT 1 May 5th, 2009 12:55 AM
Removing leading zeros from a string value vikkiefd XSLT 2 June 12th, 2008 03:30 AM
Remove Leading and Trailing Zeros lene_wee SQL Server 2000 3 April 1st, 2008 08:23 AM
remove characters from "=" and before ymeyaw Excel VBA 2 February 27th, 2007 06:02 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.