簡體   English   中英

XSLT 1.0代碼流

[英]XSLT 1.0 code flow

我想知道當您處於模板中並調用另一個模板以檢索值,然后繼續處理第一個模板並使用另一個模板捕獲的值時,如何執行代碼。 誰能提供此設置的有效示例?

一個示例可能是:

<xsl:template name="test">

    <xsl:choose>

        <xsl:when test="boolean(.)">

            <xsl:variable name="list" select="'want to store this and return to previous template'"/>
        </xsl:when>
        <xsl:otherwise/>

    </xsl:choose>

</xsl:template>

<xsl:template match="/">

<file_item_nbr>
     <xsl:call-template name="test">
 </xsl:call-template>
     <xsl:value-of select="$test"/>
</file_item_nbr>

</xsl:template>

我的實際案例比我所舉的例子要遠得多。 我希望能夠在連字符(-)之后獲取父節點號,並將該整數值傳遞回原始模板,然后將變量增加特定的數字。

您有一個簡單的變量作用域問題。

變量的作用域是其直接父級。 它們不存在於其外部。

只是扭轉你的方法。 畢竟,您希望變量內容取決於模板調用。 變量本身必須在要使用它的位置聲明。

<xsl:template name="test">
  <xsl:choose>
    <xsl:when test="boolean(.)">
      <xsl:value-of select="'want to store this and return to previous template'" />
    </xsl:when>
    <xsl:otherwise>
      <xsl:value-of select="'maybe I want to store something else here'" />
    </xsl:otherwise>
  </xsl:choose>
</xsl:template>

<xsl:template match="/">
  <file_item_nbr>

    <xsl:variable name="result">
      <xsl:call-template name="test" />
    </xsl:variable>

    <xsl:value-of select="$result"/>
  </file_item_nbr>
</xsl:template>

請注意,執行xsl:call-template> (即的含義)時,當前節點不會更改. 保持與調用模板中的相同。


修改<xsl:call-template>結果的兩種方法是

<xsl:variable name="temp">
  <xsl:call-template name="test" />
</xsl:variable>

<xsl:variable name="result">
  <xsl:value-of select="$temp + 2" />
</xsl:variable>

或者,通過嵌套變量更好一些:

<xsl:variable name="result">
  <xsl:variable name="temp">
    <xsl:call-template name="test" />
  </xsl:variable>
  <xsl:value-of select="$temp + 2" />
</xsl:variable>

暫無
暫無

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

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