I've got this code (which is working properly):
<xsl:template name="CamelChain">
<xsl:param name="input"/>
<xsl:param name="position"/>
<xsl:if test="$position <= string-length($input)">
<xsl:choose>
<xsl:when test="substring($input, $position, 1) = '_'">
<xsl:value-of select="translate(substring($input, $position + 1, 1), 'abcdefghijklmnopqrstuvwxyz', 'ABCDEFGHIJKLMNOPQRSTUVWXYZ')"/>
<xsl:call-template name="CamelChain">
<xsl:with-param name="input" select="$input"/>
<xsl:with-param name="position" select="$position + 2"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="substring($input, $position, 1)"/>
<xsl:call-template name="CamelChain">
<xsl:with-param name="input" select="$input"/>
<xsl:with-param name="position" select="$position + 1"/>
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
</xsl:if>
</xsl:template>
And i attempted to normalize it abit as such:
<xsl:template name="CamelChain">
<xsl:param name="input"/>
<xsl:param name="position"/>
<xsl:if test="$position <= string-length($input)">
<xsl:choose>
<xsl:when test="substring($input, $position, 1) = '_'">
<xsl:value-of select="translate(substring($input, $position + 1, 1), 'abcdefghijklmnopqrstuvwxyz', 'ABCDEFGHIJKLMNOPQRSTUVWXYZ')"/>
<xsl:variable name="jump" select="2"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="substring($input, $position, 1)"/>
<xsl:variable name="jump" select="1"/>
</xsl:otherwise>
</xsl:choose>
<xsl:call-template name="CamelChain">
<xsl:with-param name="input" select="$input"/>
<xsl:with-param name="position" select="$position + $jump"/>
</xsl:call-template>
</xsl:if>
</xsl:template>
But after I've "normalized" it.. it's not working anymore. I suspect its got something to do with the select="$position + $jump"
portion but i'm not sure what's wrong with it. does anyone know what's wrong?
Your two
$jump
variables each go out of scope before you reference them.In XSLT as in any block-structured language a variable has a scope, out of which it is undefined.
here you are defining the
$jump
variable at the very end of its scope and it immediately ceases to exist. This is an obvious error and Some XSLT processors as Saxon even issue a warning message about this.You have exactly the same problem with the other variable (also named
$jump
) definition.Your problem is that the variable
$jump
is out of scope. You can't set variables inside axsl:choose
, and expect their value to persist outside. I believe you have to edit the middle section like this:The
xsl:choose
must go within thexsl:variable
, not the other way around.To be honest though, I can't see anything objectionable with your original code. It looks cleaner to me.