[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: "Kenny Akridge" <kakridge@xxxxxxxxxxxxx>
Date: Wed, 4 Feb 2004 02:41:08 -0500
xsl count characters
I'm sure there is an easier solution that I'm not aware of, but this
will certainly work:

<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
	<xsl:apply-templates select="name">
		<xsl:with-param name="count" select="'11'"/>
	</xsl:apply-templates>
</xsl:template>

<xsl:template match="name">
	<xsl:param name="count"/>
	<xsl:choose>
		<xsl:when test="$count &lt; string-length(.) ">
			<xsl:value-of select="substring(., ($count -
10), 10)"/>
			<br/>
			<xsl:apply-templates select="//name">
				<xsl:with-param name="count"
select="$count + 10"/>
			</xsl:apply-templates>
		</xsl:when>
		<xsl:otherwise>
			<xsl:value-of select="substring(., ($count -
10), 10)"/>
		</xsl:otherwise>
	</xsl:choose>
</xsl:template>
</xsl:stylesheet>

Just substitute &#160; or &#xA0; for <br/> if you want spaces.

-Kenny Akridge

-----Original Message-----
From: owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx
[mailto:owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx] On Behalf Of
allan.mccluskey@xxxxxxxxxxxxxxxxx
Sent: Wednesday, February 04, 2004 1:59 AM
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject:  Long string - inserting a space after every 10 characters

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

OR /

Example2
<name>Thisisanotherexceptionallylongname</name>

Would loook like:
Thisisanot&#160;herexcepti&#160;onallylong&#160;name

Many, many thanks
Al








Important:  This e-mail is intended for the use of the addressee and may
contain information that is confidential, commercially valuable or
subject to legal or parliamentary privilege.  If you are not the
intended recipient you are notified that any review, re-transmission,
disclosure, use or dissemination of this communication is strictly
prohibited by several Commonwealth Acts of Parliament.  If you have
received this communication in error please notify the sender
immediately and delete all copies of this transmission together with any
attachments.


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


 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.