开发者

XSLT: Call template with parameter from template which provides the paramenter

开发者 https://www.devze.com 2023-03-06 04:56 出处:网络
I would like to call template2 from inside template1, and provide it with a parameter from template1.

I would like to call template2 from inside template1, and provide it with a parameter from template1.

Right now, I have something like this:

<xsl:template name="template1" match="home/sentences/sentence">
        <xsl:if test="something...">
            <new_sentence>  
                <!-- ...other unrelated stuff... -->

                <xsl:apply-templates select="key('get_sentence_attribute', tokenRef/@tokID)"/>

                <!--Here I point to the template I made for tokens. 
                But I also wish to provide it with the value returned by get_sentence_attribute -->
                <xsl:apply-templates select="../../tokens"/>
            </new_sentence>
        </xsl:if>
</xsl:template>

<xsl:template name="template2" match="home/tokens">
      <!-- ... -->
</xsl:template>

Basically I need to make sure that the values selected by my tokens template, match the sentence_attribute I get in my sentence template. I've googled around and found the <xsl:开发者_Go百科with-param> element; but it's pretty confusing to me and I'm not even sure if it's what I need.

Thanks for any help!


<!-- 1. store your results in a variable -->
<xsl:variable name="result">
<xsl:apply-templates select="key('get_sentence_attribute', tokenRef/@tokID)"/>
</xsl:variable>

<!-- 2. call your template with a param value -->
<xsl:call-template name="named-template">
    <xsl:with-param name="param1" value="$result"/>
</xsl:call-template/>

...
...

<!-- 3. you need to declare your template to accept a parameter -->
<xsl:template name="named-template">
    <xsl:param name="param1"/>

    <!-- do stuff with $param1-->
</xsl:template>
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号