簡體   English   中英

在XSL中訪問參數值

[英]Accessing value of param in xsl

我正在嘗試從以下代碼中獲取名為Round的模板的參數值,但是它返回空白,有人可以告訴我如何在模板中獲取參數的值

<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>

實際上,這可行。 我嘗試如下。 添加其他必要的內容,例如樣式表根元素。

<?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>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM