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

RE: Formatting string

Subject: RE: Formatting string
From: "Babu Eswaramoorthy" <babueswaramoorthy@xxxxxxx>
Date: Thu, 17 May 2007 10:08:36 +0800
RE:  Formatting string
Thanks to All. The problem is resolved. I have learned many tips from
all you solution.

Thanks again,
Babu

-----Original Message-----
From: Mukul Gandhi [mailto:gandhi.mukul@xxxxxxxxx]
Sent: Thursday, May 17, 2007 1:12 AM
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: Re:  Formatting string

Following is another XSLT 1.0 solution:

<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">

  <xsl:output method="text" />

  <xsl:variable name="caps" select="'ABCDEFGHIJKLMNOPQRSTUVWXYZ'" />

  <xsl:template match="x">
     <xsl:call-template name="formatString">
       <xsl:with-param name="s" select="string" />
       <xsl:with-param name="result" select="''" />
     </xsl:call-template>
  </xsl:template>

  <xsl:template name="formatString">
     <xsl:param name="s" />
     <xsl:param name="result" />

     <xsl:choose>
       <xsl:when test="string-length($s) = 0">
         <xsl:value-of select="$result" />
       </xsl:when>
       <xsl:otherwise>
         <xsl:choose>
           <xsl:when test="(string-length($s) = string-length(string))
and contains($caps, substring($s, 1, 1))">
             <xsl:call-template name="formatString">
	<xsl:with-param name="s" select="substring($s, 2)" />
	<xsl:with-param name="result" select="concat($result,
substring($s, 1, 1))" />
             </xsl:call-template>
           </xsl:when>
           <xsl:when test="contains($caps, substring($s, 1, 1))">
             <xsl:call-template name="formatString">
	<xsl:with-param name="s" select="substring($s, 2)" />
	<xsl:with-param name="result" select="concat($result, ' ',
substring($s, 1, 1))" />
             </xsl:call-template>
           </xsl:when>
           <xsl:otherwise>
             <xsl:call-template name="formatString">
	<xsl:with-param name="s" select="substring($s, 2)" />
	<xsl:with-param name="result" select="concat($result,
substring($s, 1, 1))" />
             </xsl:call-template>
           </xsl:otherwise>
         </xsl:choose>
       </xsl:otherwise>
     </xsl:choose>
  </xsl:template>

</xsl:stylesheet>

This when applied to the XML:

<x>
 <string>BankOfAmerica</string>
</x>

Produces output:

Bank Of America

On 5/16/07, Babu Eswaramoorthy <babueswaramoorthy@xxxxxxx> wrote:
>
> Hi All,
>
>
> Is there any way to add a space before Capital letters of a string?
>
> for example my input string is "BankersGuarantee" and I want the
result
> as "Bankers Guarantee"
> Another example..... the input string is "BankOfAmerica" and I want
the
> result as "Bank Of America"
>
>
> Can anyone help me to implement the above logic in xsl.
>
> Thanks in advance,
> Babu


--
Regards,
Mukul Gandhi



CONFIDENTIAL NOTE: The information contained in this email is intended only
for the use of the individual or entity named above and may contain
information that is privileged, confidential and exempt from disclosure under
applicable law. If the reader of this message is not the intended recipient,
you are hereby notified that any dissemination, distribution or copying of
this communication is strictly prohibited. If you have received this message
in error, please immediately notify the sender and delete the mail.
Thank you.

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.