2016-08-11 68 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

感謝您的幫助和鏈接! –