是否可以將指定模板的參數指定爲另一個模板中的匹配模式?將模板參數命名爲用於模板匹配的XPath
在這裏,如果我嘗試調用「摘錄」模板,並在XPath傳遞的「路徑」 PARAM,我得到一個錯誤:
<xsl:template name="excerpt">
<xsl:param name="path" select="''" />
<xsl:apply-templates select="$path" />
</xsl:template>
<xsl:template match="$path">
<article class="newsarticle">
<h2><a href="{$root}/news/view/{title/@handle}"><xsl:value-of select="title" /></a></h2>
<xsl:copy-of select="excerpt/node()" />
</article>
</xsl:template>
我可以<xsl:for-each>
完成它,但我想知道如果有一個很好的解決方案,使用類似於上面的方法。
編輯:這裏就是我試圖完成,有<xsl:for-each>
工作:
<xsl:template name="excerpt">
<xsl:param name="path" select="''" />
<xsl:for-each select="$path">
<article class="newsarticle">
<h2><a href="{$root}/news/view/{title/@handle}"><xsl:value-of select="title" /></a></h2>
<xsl:copy-of select="excerpt/node()" />
</article>
</xsl:for-each>
</xsl:template>
編輯:調用模板的一個例子:
<xsl:call-template name="excerpt">
<xsl:with-param name="path" select="path/to/nodeset" />
</xsl:call-template>
你能提供一個例子,說明如何使用for-each來完成你想要的任務嗎? – JLRishe
感謝您的額外細節。你能否提供一個調用該模板的例子? – JLRishe