|
[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
Hi Allan,
Sorry for late response. Following is another
solution to the problem -
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text" encoding="UTF-8"
indent="yes"/>
<xsl:template match="/name">
<xsl:call-template name="process-string">
<xsl:with-param name="string-subset" select="."/>
<xsl:with-param name="n" select="10"/>
</xsl:call-template>
</xsl:template>
<xsl:template name="process-string">
<xsl:param name="string-subset"/>
<xsl:param name="n"/>
<xsl:value-of select="substring($string-subset, 1,
$n)"/>
<xsl:text> </xsl:text>
<xsl:variable name="strlen"
select="string-length(substring($string-subset, $n +
1, string-length($string-subset)))"/>
<xsl:if test="$strlen > 9">
<xsl:call-template name="process-string">
<xsl:with-param name="string-subset"
select="substring($string-subset, $n + 1,
string-length($string-subset))"/>
<xsl:with-param name="n" select="10"/>
</xsl:call-template>
</xsl:if>
<xsl:if test="not($strlen > 9)">
<xsl:value-of select="substring($string-subset,
$n + 1, string-length($string-subset))" />
</xsl:if>
</xsl:template>
</xsl:stylesheet>
I have used a recursive template..
Regards,
Mukul
--- allan.mccluskey@xxxxxxxxxxxxxxxxx wrote: > 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 (?) 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?herexcepti?onallylong?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
>
________________________________________________________________________
Yahoo! India Mobile: Download the latest polyphonic ringtones.
Go to http://in.mobile.yahoo.com
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|

Cart








