2013-03-18 15 views
0

我想從下面的代碼中得到名爲「Round」的模板的參數值,但它返回空白,有人可以告訴我如何獲取模板中參數的值在xsl中訪問param的值

<xsl:apply-templates select="//solution"> 
      <xsl:with-param name="isRound">N</xsl:with-param> 
</xsl:apply-templates> 

    <xsl:template match="solution"> 
    <xsl:param name="isRound" /> 
    <test> 
     <xsl:value-of select="$isRound"/> 
    </test> 
    </xsl:template> 

的這個輸出是:

<test></test> 
+0

你能告訴我們更多的XSLT的?至少包含'xsl:apply-templates'的所有模板,以及層次結構中的更多級別?也許你在那裏的'apply-templates'沒有被使用,'solution'被自己匹配 – JLRishe 2013-03-18 20:51:14

回答

1

其實這個工作。我嘗試如下。添加其他必要的東西,如樣式表根元素。

<?xml version="1.0" encoding="UTF-8"?> 
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 

    <xsl:template match="/root"> 
     <xsl:apply-templates select="//solution"> 
      <xsl:with-param name="isRound">N</xsl:with-param> 
     </xsl:apply-templates> 
    </xsl:template> 

    <xsl:template match="solution"> 
     <xsl:param name="isRound" /> 
      <test> 
       <xsl:value-of select="$isRound"/> 
      </test> 
    </xsl:template> 
</xsl:stylesheet> 

輸入例如。

<root> 
    <solution/> 
</root> 

結果

<?xml version="1.0"?> 
<test>N</test>