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

Re: String Manipulation in XSL

Subject: Re: String Manipulation in XSL
From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx>
Date: Fri, 26 Oct 2001 12:43:53 -0400
xml string manipulation
At 01/10/26 17:35 +0100, Peter.FLYNN@xxxxxxxxxxxx wrote:
I was wondering if anyone had a solution for this problem.  I get an element
through which has a string which can be variable length.  It could be 20
characters long, 40, 60, upto anything really.

I'm wanting to put in a space every 20 characters, and am unsure on how to
do this.

Using a recursive call, you can act on a string, reducing the amount of the string not yet acted upon for the next call.


I hope the code fragment below helps illustrate this. You don't mention what you want done at the end of the string, or any other nuances, but this should give you what you need to get started.

................. Ken

T:\ftemp>type peter.xml
<?xml version="1.0" encoding="utf-8"?>
<value>12345678901234567890123456789012345678901234567</value>
T:\ftemp>type peter.xsl
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                version="1.0">

<xsl:template match="/">
  <xsl:call-template name="do-a-string">
    <xsl:with-param name="string" select="/value"/>
  </xsl:call-template>
</xsl:template>

<xsl:template name="do-a-string">
  <xsl:param name="string"/>
  <xsl:if test="$string">
    <xsl:value-of select="substring($string,1,20)"/>
    <xsl:text> </xsl:text>
    <xsl:call-template name="do-a-string">
      <xsl:with-param name="string" select="substring($string,21)"/>
    </xsl:call-template>
  </xsl:if>
</xsl:template>

</xsl:stylesheet>

T:\ftemp>saxon peter.xml peter.xsl
<?xml version="1.0" encoding="utf-8"?>12345678901234567890 12345678901234567890 1234567
T:\ftemp>




--
G. Ken Holman                      mailto:gkholman@xxxxxxxxxxxxxxxxxxxx
Crane Softwrights Ltd.               http://www.CraneSoftwrights.com/s/
Box 266, Kars, Ontario CANADA K0A-2E0     +1(613)489-0999   (Fax:-0995)
Web site:     XSL/XML/DSSSL/SGML/OmniMark services, training, products.
Book:  Practical Transformation Using XSLT and XPath ISBN 1-894049-06-3
Article: What is XSLT? http://www.xml.com/pub/2000/08/holman/index.html
Next public training (instructor-live, Internet-live, and web-based):
-2001-10-22,11-01,11-02,11-05,11-19,11-21,12-03,12-05,12-09,12-10,12-19


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.