Kevin
Kevin

Reputation: 215

XSL - How do you capitalize accented letters

I have following xml.

<surname>\`{a}bcd efgh</surname>

I want to capitalize first letter and output in following format.

<surname>\`{A}bcd Efgh</surname>

I am using the following code

<xsl:sequence select="string-join(for $x in tokenize($textone,'\s') return my:titleCase($x),' ')"/>

Upvotes: 0

Views: 103

Answers (1)

Tim C
Tim C

Reputation: 70618

You could use analyze-string to look for the first occurence of a letter in a string.

Try this XSLT

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                xmlns:my="my-functions">
<xsl:output method="text" />

<xsl:function name="my:titleCase">
  <xsl:param name="string"/>
  <xsl:analyze-string select="$string" regex="^([^A-Za-z]*)([A-Za-z])(.*)$">
    <xsl:matching-substring>
      <xsl:value-of select="concat(regex-group(1), upper-case(regex-group(2)), regex-group(3))" />
    </xsl:matching-substring>
  </xsl:analyze-string>
</xsl:function>

<xsl:template match="text()">
<xsl:variable name="textone" select="." />
<xsl:sequence select="string-join(for $x in tokenize($textone,'\s') return my:titleCase($x),' ')"/>
</xsl:template>
</xsl:stylesheet>

Upvotes: 1

Related Questions