Converting All-Capitals to Title Case

Novell Cool Solutions: Tip
By Lothar Haeger

Digg This - Slashdot This

Posted: 22 Feb 2006


A reader described the following situation:

"I have a problem with the delimited text driver, when the input has attributes written in all capital letters and I need to convert them to title case. I have managed to change attributes with just one word to "Title Case" using reformat in Transformation policy, but some attibutes have more than one word. For example, Firstnames = "JOHN PETER" goes to = "John peter" using reformat.

How do I detect the space and change the second, third, etc. words' first letters to uppercase? Should I write a Input transformation policy using XSL template that converts a string from "ALL CAPITAL LETTERS" to "Title Case"?"

And here's the response from Lothar Haegar ...


If you can live with a less than 100%-solution, something like this might work for you:

        <do-reformat-op-attr name="UPPERCASE">
                <token-replace-all regex="\ba" replace-with="A">
                <token-replace-all regex="\bb" replace-with="B">
                <token-replace-all regex="\bc" replace-with="C">
                        <token-local-variable name="current-value"/>
                        [another 23x...]

Note that "\b" matches word boundaries. Take a look at the following reference; it helped me a lot:

Novell Cool Solutions (corporate web communities) are produced by WebWise Solutions. www.webwiseone.com

© Micro Focus