dperkalis
unread,Oct 31, 2008, 3:21:45 PM10/31/08Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Sign in to report message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to xml and xslt
I recently had the need to convert an all CAPS string to UpperLower
Case. ie. THIS IS MY STRING -> This Is My String.
I couldn't find anything to do it in XSL 1.0, so I wrote the following
if anyone finds it helpful:
<xsl:template name="ToUpperLowerCase">
<xsl:param name="inputString"/>
<xsl:param name="index"/>
<xsl:param name="loopCount"/>
<xsl:if test="$index < $loopCount">
<xsl:choose>
<xsl:when test="substring($inputString, ($index)-1,1) = ' ' or
$index = 1">
<xsl:call-template name="ToUpper">
<xsl:with-param name="inputString"
select="substring($inputString,$index,1)"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:call-template name="ToLower">
<xsl:with-param name="inputString"
select="substring($inputString,$index,1)"/>
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
<xsl:call-template name="ToUpperLowerCase">
<xsl:with-param name="inputString" select="$inputString"/>
<xsl:with-param name="index" select="($index)+1"/>
<xsl:with-param name="loopCount" select="$loopCount"/>
</xsl:call-template>
</xsl:if>
</xsl:template>
<xsl:template name="ToLower">
<xsl:param name="inputString"/>
<xsl:variable name="smallCase" select="'abcdefghijklmnopqrstuvwxyz'"/
>
<xsl:variable name="upperCase" select="'ABCDEFGHIJKLMNOPQRSTUVWXYZ'"/
>
<xsl:value-of select="translate($inputString,$upperCase,
$smallCase)"/>
</xsl:template>
<xsl:template name="ToUpper">
<xsl:param name="inputString"/>
<xsl:variable name="smallCase" select="'abcdefghijklmnopqrstuvwxyz'"/
>
<xsl:variable name="upperCase" select="'ABCDEFGHIJKLMNOPQRSTUVWXYZ'"/
>
<xsl:value-of select="translate($inputString,$smallCase,$upperCase)"/
>
</xsl:template>
You can call it using the following:
<xsl:call-template name="ToUpperLowerCase">
<xsl:with-param name="inputString" select="ValueToConvert"/>
<xsl:with-param name="index" select="0"/>
<xsl:with-param name="loopCount" select="string-
length(ValueToConvert)+1"/>
</xsl:call-template>