[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: Jeff Beadle <Jbeadle@xxxxxxxx>
Date: Thu, 21 Mar 2002 08:32:56 -0500
isnan xsl
Hey Katie,

Here's an approach that works well for ANSI characters.

I'm not totally sure how it would behave with Unicode data, I do know it
won't die--it just may not case some of the non-english characters
correctly.  I tested it out with some greek sentences, with what little I
know about greek characters, and it seems to be behaving correctly.
However, be wary, because I believe that some languages have characters that
have no equivalent capitalized form ... in which case, I suspect this
function will still work--it should just no-op the toUpperCase call to
return the given character as is.

Anyway, enough of my jibber-jabber, here's the extension function:

 <msxsl:script implements-prefix="string" language="JavaScript">
//<![CDATA[
function toAllWordsProperCase(s){

    if(void(0)==s||null==s) return "";
	
    if("object"==typeof(s)) s = s.nextNode.text;

    if(void(0)==s||""==s) return "";

    var result = "";
    var words = s.split(" ");
    var count = words.length;

    for(var i=0;i<count;i++) {
       result += parse(words[i]) + " ";
    }
    result += parse(words[i]);

    return result;

    ////////////////////////////////////////
    //internal method
    function parse(s){
       if(void(0)==s||""==s) return "";
       if(isNaN(parseInt(s))) {
          return s.charAt(0).toUpperCase() + s.substr(1).toLowerCase();
       }
       else {
          return s;
       }
    }
}
//]]>
</msxsl:script>


hope this helps ... I know I enjoyed the exercise.

-Jeff


-----Original Message-----
From: Katie McNally [mailto:kmcnally9@xxxxxxxxxxx]
Sent: Wednesday, March 20, 2002 8:43 PM
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject:  Capitalizing only the first letter of each word


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


_________________________________________________________________
MSN Photos is the easiest way to share and print your photos: 
http://photos.msn.com/support/worldwide.aspx


 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.