如果我有一个模板,如下所示,用于创建一个按钮:
<xsl:template match="button" name="button"> <a class="button" href="{@href}"> <xsl:value-of select="@name"/> </a> </xsl:template>
我希望能够在另一个模板中使用该按钮,如下所示:
<xsl:template match="createForm"> ... <button name="Create" href="/create"/> </xsl:template>
但是,这只会按原样输出按钮标记.我希望通过现有的按钮模板进行处理.怎么能实现这一目标?
–
感谢David M的回答.这是我现在用于按钮模板的内容:
<xsl:template match="button" name="button"> <xsl:param name="name" select="@name"/> <xsl:param name="href" select="@href"/> <a class="button" href="{$href}"> <xsl:value-of select="$name"/> </a> </xsl:template>
createForm模板现在看起来像这样:
<xsl:template match="createForm"> ... <xsl:call-template name="button"> <xsl:with-param name="name" select="'Create'"/> </xsl:call-template> </xsl:template>
@R_403_323@
尝试使用它(在我的头顶):
<xsl:call-template name="button"> <xsl:with-param name="name" value="Create" /> <xsl:with-param name="href" value="/create" /> </xsl:call-template>
您还需要使用< xsl:param ...>在按钮模板中声明两个参数.