2013-07-23 68 views
0

我的XSLT 1.0代碼 -店輸出到XSLT變量

<Test1> 
    <xsl:text>"</xsl:text> 
    <xsl:choose> 
     <xsl:when test="/root/node1">B</xsl:when> 
     <xsl:when test="/root/node2">S</xsl:when> 
     <xsl:otherwise>NA</xsl:otherwise> 
    </xsl:choose> 
    <xsl:text>"</xsl:text>  
</Test1> 

我想上面的節點<Test1>的輸出存入一個變量。事情是這樣的,

<xsl:variable name="test"> 
    <xsl:value-of select="??"/> 
</xsl:variable> 

使用此變量的值來計算其他的東西或者顯示值,

<Test2> 
    <xsl:text>"</xsl:text> 
    <xsl:value-of select="$test"/> 
    <xsl:text>"</xsl:text> 
</Test2> 

我應該寫的,而不是??什麼來獲取節點<Test1>的價值?或者還有什麼其他方法可以將節點的輸出值讀入XSLT中的變量?

回答

0

我覺得你只是想

<xsl:variable name="test"> 
    <xsl:text>"</xsl:text> 
    <xsl:choose> 
     <xsl:when test="/root/node1">B</xsl:when> 
     <xsl:when test="/root/node2">S</xsl:when> 
     <xsl:otherwise>NA</xsl:otherwise> 
    </xsl:choose> 
    <xsl:text>"</xsl:text> 
</xsl:variable> 

然後

<Test2> 
    <xsl:text>"</xsl:text> 
    <xsl:value-of select="$test"/> 
    <xsl:text>"</xsl:text> 
</Test2> 

你可以使用的包裝元素節點,但它並沒有改善的事情,如果你只是想處理一些字符串像BNA

+0

我有'Test1'這樣的多個節點,並且不想複製代碼以將值讀入變量。你能提出其他建議嗎?提前致謝。 –

+1

您可以將值存儲在變量,甚至是節點中。但至少在XSLT 1.0處理器中,您最終會得到結果樹碎片,您可以在其上使用「copy-of」或「value-of」。我不確定你想如何使用你的變量,因爲你已經顯示的情況下,我認爲我的建議已經足夠,請編輯你的問題更多的細節。 –