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

Re: Capitalizing only the first letter of each word

Subject: Re: Capitalizing only the first letter of each word
From: Ingo Schildmann <Ingo.Schildmann@xxxxxxxxxxxxx>
Date: Thu, 21 Mar 2002 15:22:07 +0100
xsl first letter uppercase
On Thursday 21 March 2002 02:42, you wrote:
> I am getting back my data in ALL-CAPS.  Is there any way to display the
> first letter of each word in uppercase, but the rest of each word in
> lowercase?
>
> example XML:
>
> <Tg Nm="Name">JOHN LEWIS</Fld>
> <Tg Nm="Street">8780 MAIN ST</Fld>
> <Tg Nm="City">COLORADO SPRINGS</Fld>
> <Tg Nm="State">CO</Fld>
>
> I want to display:
>
> John Lewis
> 8780 Main St
> Colorado Springs
> CO
>

Here is a sketched (means not tested) XSLT solution,
with apologies to Scotts(McD..), Irishs(O'H..) and people from IJsselstein:-).
Imho you shouldn't change the strings because you risk to falsify the data,
the problem is the loss of cases in the process before.

Call template caseUp with a string you want to convert.
Every char that's not at the beginning or after a space is decapitalized.

<xsl:template name="caseDown">
    <xsl:param name="data"/>
    <xsl:if test="$data">
       <xsl:choose>
        <xsl:when test="starts-with($data,' ')"> 
            <xsl:text> </xsl:text> 
            <xsl:call-template name="caseUp">
               <xsl:with-param name="data" select="substring($data,2)"/>
            </xsl:call-template>
        </xsl:when>
        <xsl:otherwise>
            <xsl:value-of select="translate(substring($data,1,1),
                                  'ABCDE....XYZ','abcde...xyz')"/>
            <!-- put all the chars you want to change 
                 into the last two strings -->        
            <xsl:call-template name="caseDown">
               <xsl:with-param name="data" select="substring($data,2)"/>
            </xsl:call-template>
        </xsl:otherwise>
       </xsl:choose>
    </xsl:if>  
</xsl:template>

<xsl:template name="caseUp">
   <xsl:param name="data"/>
   <xsl:if test="$data">
	<xsl:value-of select="substring($data,1,1)"/>
        <xsl:call-template name="caseDown"> 
            <xsl:with-param name="data" select="substring($data,2)"/>
        </xsl:call-template>
   </xsl:if>
</xsl:template>

   
-- 
Ingo Schildmann                       
Development
WiredMinds Informationssysteme GmbH
http://www.WiredMinds.de


 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.