是否可以将命名模板的参数指定为另一个模板中的匹配模式?
在这里,如果我尝试调用“excerpt”模板并将 XPath 作为“path”参数传递,我会收到错误消息:
<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>