xslt 如果我们执行`select=“$position + $jump"` 可以吗? [英] xslt is it ok if we do `select="$position + $jump"`?

查看:22
本文介绍了xslt 如果我们执行`select=“$position + $jump"` 可以吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个代码(工作正常):

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 &lt;= 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>

我试图将其标准化:

   <xsl:template name="CamelChain">
      <xsl:param name="input"/>
      <xsl:param name="position"/>
      <xsl:if test="$position &lt;= 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>

但是在我规范化"它之后..它不再起作用了.我怀疑它与 select="$position + $jump" 部分有关,但我不确定它有什么问题.有谁知道怎么回事?

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?

推荐答案

你的两个 $jump 变量在你引用它们之前都会超出范围.

Your two $jump variables each go out of scope before you reference them.

在 XSLT 中,就像在任何块结构语言中一样,变量都有一个范围,在该范围之外它是未定义的.

In XSLT as in any block-structured language a variable has a scope, out of which it is undefined.

    <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>

在这里,您在其作用域的最后定义了 $jump 变量,它立即不复存在.这是一个明显的错误,Saxon 等一些 XSLT 处理器甚至会发出警告消息.

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.

对于另一个变量(也称为 $jump)定义,您遇到了完全相同的问题.

You have exactly the same problem with the other variable (also named $jump) definition.

这篇关于xslt 如果我们执行`select=“$position + $jump"` 可以吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆