Posted By

Meander365 on 08/02/09


Tagged

XSL uppercase lowercase


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

Tyster


Convert String to Upper Lower Case in XSL


 / Published in: XSLT
 

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

Convert a string into upper lower case. So

hello world = Hello World

  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>

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: bmorton2078 on December 23, 2009

This is exactly what I need; however, I'm having problems getting it to work (newbie). Please help. I have the following:

xsl:

Posted By: bmorton2078 on December 23, 2009

This is exactly what I need; however, I'm having problems getting it to work (newbie). Please help. I have the following:

xsl:

You need to login to post a comment.