what's a better way to write this code:
<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>
Ok its clean but I believe it can be cleaner. Say right now I'm repeating this logic:
<xsl:call-template name="CamelChain">
<xsl:with-param name="input" select="$input"/>
<xsl:with-param name="position" select="$new_position"/>
</xsl:call-template>
So basically does anyone have any solution?
I've actually tried it myself @ xslt is it ok if we do `select="$position + $jump"`? but that method (or hack as i call it) is not working.. so i'm currently out of solutions and was wondering if someone could help.
Basically I was thinking along the lines of:
<xsl:template name="CamelChain">
<xsl:param name="input"/>
<xsl:param name="position"/>
<xsl:variable name="jump"/>
<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')"/>
<!-- set jump to 2 -->
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="substring($input, $position, 1)"/>
<!-- set jump to 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>
or well maybe something totally different or exotic. (XSLT 1.0 without extensions here)
As @Michael-Key clearly states, string manipulation in XSLT 1.0 is verbous (well, tedious..depends :).
I've looked at your template and I think is not that easy to obtain just once the template recursive invocation inside the template scope, unless you change your mind on how you have designed the template.
Do note also that your template is not going to upper case the first letter of the input word. Is that wanted?
However, with risk of being even more tedious and verbose, I want to show you this approach where:
_
and not once for each character as your does (apparently isnt?)For instance, if you call it as:
it will return:
A better way is to write it in XSLT 2.0:
I'm afraid however hard you try, solving character manipulation problems in XSLT 1.0 is going to be tedious and verbose.