2010-08-18 69 views
1

是否可以在xslt中的變量內創建一個變量?變量在xslt編碼中的變量

是上面的事可能???

+1

的問題已經以低於票面價值得到回答,但我不知道你究竟意欲何爲?也許如果你更詳細地描述你需要的東西,我們可以給出更好的答案。 – LarsH 2010-08-18 18:01:42

回答

4

這是你的意思嗎?

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" exclude-result-prefixes="xs" xmlns:xd="http://www.oxygenxml.com/ns/doc/xsl" version="2.0"> 

    <xsl:variable name="a"> 
    <xsl:variable name="b" select="10"/> 
    <xsl:value-of select="$b"/> 
    </xsl:variable> 

    <xsl:template match="/"> 
    <xsl:value-of select="$a"/> 
    </xsl:template> 

</xsl:stylesheet> 

答案是肯定的,但內變量是在範圍僅內外部變量的定義。因此,如果外部變量的定義需要一些複雜的表達式,並且需要臨時存儲(可能用於調試目的),那麼這是一種方法。

1

答案是肯定的。這個樣式表:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 
    <xsl:output method="text"/> 
    <xsl:template match="/"> 
     <xsl:variable name="vOuter"> 
      <xsl:variable name="vInner"> 
       <xsl:value-of select="'Content'"/> 
      </xsl:variable> 
      <xsl:value-of select="concat('Some ',$vInner)"/> 
     </xsl:variable> 
     <xsl:value-of select="$vOuter"/> 
    </xsl:template> 
</xsl:stylesheet> 

輸出:

Some Content