Thursday, July 17, 2008

Uppercase in XSLT

XPATH doesn't have a built in ToUpper() or ToLower() function.  However, you can use the translate function to switch cases.  Here's an example that changes the word "Upper" to all upper case.

<xsl:variable name="text" select="'Upper'" />
<xsl:value-of select="translate($text, 'abcdefghijklmnopqrstuvwxyz', 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'" />

If you want to go the other way and lowercase your string, just flip-flop the alphabet strings.

<xsl:variable name="text" select="'Upper'" />
<xsl:value-of select="translate($text, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz'" />

Song of the day:
Twilight Zone(Live) - Golden Earring - The Naked Truth

1 comment:

Anonymous said...

What are the odds I'd come across a blog post by you out here?

-John J