Tuesday 1 May 2012

Initial caps string conversion using XSLT 2.0


<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:xs="http://www.w3.org/2001/XMLSchema" exclude-result-prefixes="xs" version="2.0">
<xsl:template match="/">
  <xsl:param name="string" select="'my name Is vishnu singh'"/>
  <xsl:param name="token" select="tokenize($string, ' ')"/>
 
  <!--using xslf for-each-->
  <xsl:for-each select="$token">
    <xsl:sequence select="concat(upper-case(substring(.,1,1)),lower-case(substring(.,2)))"/>
  </xsl:for-each>
 
 
  <!--using xquery expression within xsl:value-of -->
  <xsl:value-of select="string-join(for $x in tokenize($string, ' ')
                                    return concat(upper-case(substring($x, 1, 1)), lower-case(substring($x, 2)))
                                    , ' ')"></xsl:value-of>
</xsl:template>

</xsl:stylesheet>

3 comments:

Unknown said...

Good Vishnu

Loralon said...

How to apply this a set of files in a folder?

I need to convert only the titles of my xml files.

Thanks

Loralon said...

Thanks for this post,

Is it possible to apply this approach to a bunch of files in a folder?

I need to convert to Title Case the titles of XML files.

Thanks