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

Re: Looping over characters in a string

Subject: Re: Looping over characters in a string
From: Jeni Tennison <mail@xxxxxxxxxxxxxxxx>
Date: Thu, 10 May 2001 09:14:24 +0100
string remove first x characters
Hi Theodore,

> Is it possible to loop over characters in a string?

Jarno's shown you two ways of doing it using an increasing index.  The
third way is to use a recursive template that walks over the string,
removing the first character from the string with each recursion.  For
example:

<xsl:template name="add-X">
   <xsl:param name="string" select="." />
   <xsl:if test="$string">
      <xsl:text>X</xsl:text>
      <xsl:call-template name="add-X">
         <xsl:with-param name="string"
                         select="substring($string, 2)" />
      </xsl:call-template>
   </xsl:if>
</xsl:template>

How exactly you use this template depends on where you are to start
with. For example, you could use it in the template matching the tag
element (the advantage of this is that it means you don't have to pass
a parameter to the template, as I've set the default for the $string
parameter to be the string value of the current node).

<xsl:template match="tag">
   <xsl:call-template name="add-X" />
   <xsl:value-of select="." />
</xsl:template>

No ASCII art I'm afraid.  Hope that helps anyway,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/



 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


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.