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>
精彩评论