编写此代码的更好方法是什么:
<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>
还行,很干净,但我相信还可以cleaner。现在我正在重复这个逻辑:
<xsl:call-template name="CamelChain">
<xsl:with-param name="input" select="$input"/>
<xsl:with-param name="position" select="$new_position"/>
</xsl:call-template>
那么基本上有人有任何解决方案吗?
我自己其实也试过@xslt 如果我们执行 `select="$position + $jump"` 可以吗? https://stackoverflow.com/questions/6290232/xslt-is-it-ok-if-we-do-select-position-jump但该方法(或我所说的黑客)不起作用..所以我目前没有解决方案,想知道是否有人可以提供帮助。
基本上我的想法是:
<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>
或者也许是一些完全不同或充满异国情调的东西。 (此处为不带扩展的 XSLT 1.0)