Convert String to Upper Lower Case in XSL


/ Published in: XSLT
Save to your folder(s)

Convert a string into upper lower case. So

hello world = Hello World


Copy this code and paste it in your HTML
  1. <xsl:template name="ToUpperLowerCase">
  2. <xsl:param name="inputString"/>
  3. <xsl:param name="index"/>
  4. <xsl:param name="loopCount"/>
  5. <xsl:if test="$index &lt; $loopCount">
  6. <xsl:choose>
  7. <xsl:when test="substring($inputString, ($index)-1,1) = ' ' or $index = 1">
  8. <xsl:call-template name="ToUpper">
  9. <xsl:with-param name="inputString" select="substring($inputString,$index,1)"/>
  10. </xsl:call-template>
  11. </xsl:when>
  12. <xsl:otherwise>
  13. <xsl:call-template name="ToLower">
  14. <xsl:with-param name="inputString" select="substring($inputString,$index,1)"/>
  15. </xsl:call-template>
  16. </xsl:otherwise>
  17. </xsl:choose>
  18. <xsl:call-template name="ToUpperLowerCase">
  19. <xsl:with-param name="inputString" select="$inputString"/>
  20. <xsl:with-param name="index" select="($index)+1"/>
  21. <xsl:with-param name="loopCount" select="$loopCount"/>
  22. </xsl:call-template>
  23. </xsl:if>
  24. </xsl:template>
  25.  
  26. <xsl:template name="ToLower">
  27. <xsl:param name="inputString"/>
  28. <xsl:variable name="smallCase" select="'abcdefghijklmnopqrstuvwxyz'"/
  29.  
  30. <xsl:variable name="upperCase" select="'ABCDEFGHIJKLMNOPQRSTUVWXYZ'"/
  31.  
  32. <xsl:value-of select="translate($inputString,$upperCase,$smallCase)"/>
  33. </xsl:template>
  34.  
  35. <xsl:template name="ToUpper">
  36. <xsl:param name="inputString"/>
  37. <xsl:variable name="smallCase" select="'abcdefghijklmnopqrstuvwxyz'"/
  38.  
  39. <xsl:variable name="upperCase" select="'ABCDEFGHIJKLMNOPQRSTUVWXYZ'"/
  40.  
  41. <xsl:value-of select="translate($inputString,$smallCase,$upperCase)"/
  42.  
  43. </xsl:template>

URL: http://groups.google.com/group/xml-and-xslt/browse_thread/thread/0b2b3a8350262213#

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.