Wednesday 8 August 2007

convert to camel case using XPath 2

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:str="http://www.metaphoricalweb.org/xmlns/string-utilities"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
version="2.0">
<xsl:function name="str:title-case" as="xs:string">
<xsl:param name="expr"/>
<xsl:variable name="tokens" select="tokenize($expr,' ')"/>
<xsl:variable name="titledTokens" select="for $token in $tokens return
concat(upper-case(substring($token,1,1)),
lower-case(substring($token,2)))"/>
<xsl:value-of select="string-join($titledTokens,'')"/>
</xsl:function>
<xsl:template match="/">
<data><xsl:value-of select="str:title-case('This is a test')"/></data>
</xsl:template>
</xsl:stylesheet>

No comments:

Post a Comment