Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

String/ALL CAPS/Change to Title Case

Status
Not open for further replies.

mulligh

Technical User
May 8, 2001
97
US
I need to change a string that contains a series of words (separated by spaces) in ALL CAPS, to title case, where only the first letter of each word is capitalized.

Example: ABSTRACTS AND PROSPECTUS to Abstracts And Prospectus

I know how to use the translate() function to drop the case of every letter, but am not sure of the best approach to do the above.

Thanks for any suggestions.

Mark
 
How do you use the translate function to convert to all caps?

(Sorry to mooch off your thread :) hehe) ________________________________________
Michael C Flanakin
Indigo Web Systems
flanakinm@indigows.com
 
Michael, first put the contents of an element into a string using the <xsl:variable> command.

Once it's in a string, you can convert it to ALL CAPS or all lowercase by using the translate function:

You would probably want to put the contents of that into another string:

<xsl:variable name=&quot;$newstring&quot;>
<xsl:value-of select=&quot;translate($firststring, 'abcdefghijklmnopqrstuvwxyz', 'ABCDEFGHIJKLMNOPQRSTUVWXYZ')&quot;/>
</xsl:variable>

This will convert $firststring to ALL CAPS and put the result in the string $newstring

 
That wouldn't work!? That would replace the entire lower case string to uppercase, but would not loop thru the variable to force upper on it. ________________________________________
Michael C Flanakin
Indigo Web Systems
flanakinm@indigows.com
 
Huh!? It doesn't need to do any &quot;looping&quot;. It just takes the entire string and replaces any characters in the first example with the characters in the second example.

Try this:

<xsl:value-of select=&quot;translate('fOur sCOre aND SeveN', 'abcdefghijklmnopqrstuvwxyz', 'ABCDEFGHIJKLMNOPQRSTUVWXYZ')&quot;/>

The output is: FOUR SCORE AND SEVEN
 
I tried it and it did not work correctly. I did explicitly tell it to uppercase the actual word, however, and that worked. Not the solution I was wanting, but I was just testing my logic (as simple as it may be). Oh well. ________________________________________
Michael C Flanakin
Indigo Web Systems
flanakinm@indigows.com
 
Make sure you are using a current XML parser. The one with IE5 by default doesn't support XSLT 1.0 specification.

IE6 has built in support for this. (If you are interested in using IE to parse your files)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top