Once upon a time, we created a function mimicking decapitalize() method defined in java in java.beans.Introspector. Nothing special, indeed. See the source:
/** * Utility method to take a string and convert it to normal Java variable * name capitalization. This normally means converting the first * character from upper case to lower case, but in the (unusual) special * case when there is more than one character and both the first and * second characters are upper case, we leave it alone. * <p> * Thus "FooBah" becomes "fooBah" and "X" becomes "x", but "URL" stays * as "URL". * * @param name The string to be decapitalized. * @return The decapitalized version of the string. */ public static String decapitalize(String name) { if (name == null || name.length() == 0) { return name; } if (name.length() > 1 && Character.isUpperCase(name.charAt(1)) && Character.isUpperCase(name.charAt(0))){ return name; } char chars[] = name.toCharArray(); chars[0] = Character.toLowerCase(chars[0]); return new String(chars); }
We typed implementation immediately:
<xsl:function name="t:decapitalize" as="xs:string"> <xsl:param name="value" as="xs:string?"/> <xsl:variable name="c" as="xs:string" select="substring($value, 2, 1)"/> <xsl:sequence select=" if ($c = upper-case($c)) then $value else concat ( lower-case(substring($value, 1, 1)), substring($value, 2) )"/> </xsl:function>
It worked, alright, until recently, when it has fallen to work, as the output was different from java's counterpart.
The input was W9Identifier. Function naturally returned the same value, while java returned w9Identifier. We has fallen with the assumption that $c = upper-case($c) returns true when character is an upper case letter. That's not correct for numbers. Correct way is:
$c = upper-case($c)
<xsl:function name="t:decapitalize" as="xs:string"> <xsl:param name="value" as="xs:string?"/> <xsl:variable name="c" as="xs:string" select="substring($value, 2, 1)"/> <xsl:sequence select=" if ($c != lower-case($c)) then $value else concat ( lower-case(substring($value, 1, 1)), substring($value, 2) )"/> </xsl:function>
Remember Me
a@href@title, b, blockquote@cite, em, i, strike, strong, sub, super, u