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

RE: Long string - inserting a space after every 10 cha

Subject: RE: Long string - inserting a space after every 10 characters
From: Jarno.Elovirta@xxxxxxxxx
Date: Wed, 4 Feb 2004 09:37:16 +0200
html long string
Hi,

> Is it possible to insert a space in a string (of unknown 
> length) after a
> specified number of characters e.g. after every 10 characters insert a
> space??
>
> I have an XML element called <name> which can be anywhere 
> between 1 and 50
> characters long. I need to either split it (by inserting a 
> <BR/> tag) or
> inserting a space (&#160;) after every 10 characters.
> 
> Example1:
> <name>Thisisareallyreallylongnamedontyouthink</name>
> 
> Would look like:
> Thisisarea<BR/>llyreallyl<BR/>ongnamedon<BR/>tyouthink

  <xsl:template match="name" name="chop">
    <xsl:param name="text" select="."/>
    <xsl:param name="delimiter">
      <br/>
    </xsl:param>
    <xsl:param name="length" select="10"/>
    <xsl:choose>
      <xsl:when test="string-length($text) > $length">
        <xsl:value-of select="substring($text, 1, $length)"/>
        <xsl:copy-of select="$delimiter"/>
        <xsl:call-template name="chop">
          <xsl:with-param name="text" select="substring($text, $length + 1)"/>
          <xsl:with-param name="delimiter">
            <xsl:copy-of select="$delimiter"/>
          </xsl:with-param>
          <xsl:with-param name="length" select="$length"/>
        </xsl:call-template>
      </xsl:when>
      <xsl:otherwise>
        <xsl:value-of select="$text"/>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>

Cheers,

Jarno - Tactical Sekt: Xfixiation (Myer Burns the Dancefloor mix by Haujobb)

 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.