This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: String Manipulation in XSL


At 01/10/26 17:35 +0100, Peter.FLYNN@syntegra.com 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@CraneSoftwrights.com
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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]