2016-08-11 64 views
0

我只是在学习xsl。我试图连接两个变量的值并在它们之间加上一个连字符。这是我的代码:xsl:将两个变量连接成新的变量

<xsl:variable name="checkboxvalue" select="translate(@value, ' ', '')" /> 
          <xsl:variable name="questionname" select="{ancestor::element/attribute::name}"/> 
      <xsl:variable name="newcheckboxvalue" select="concat($questionname,-,$checkboxvalue)"/> 

当我运行使用该.xsl文件一页面我得到 意外标记\“{\”路径表达式“‘致命错误:意外的标记\’,\”在路径表达式

感谢任何帮助。

+0

显示您的代码。 – randominstanceOfLivingThing

回答

1

你所得到的错误是由于第二个变量

<xsl:variable name="questionname" select="{ancestor::element/attribute::name}"/> 

不允许在这里使用大括号,如XSLT已经预计,在select属性的表达。你应该这样做。

<xsl:variable name="questionname" select="ancestor::element/attribute::name" /> 

或者这...

<xsl:variable name="questionname" select="ancestor::element/@name" /> 

而且,对于你的第三个说法,你需要用连字符撇号,对待它是一个字符串

<xsl:variable name="newcheckboxvalue" select="concat($questionname, '-' ,$checkboxvalue)"/> 

如果您想了解大括号的使用,请阅读Attribute Value Templates

+0

感谢您的帮助和链接! –