我有一个XSLT模板,它有条件地需要嵌套在anchor
元素中。
例如:
<xsl:choose>
<xsl:when test="$foo = 1">
<a href="/bar">
<xsl:call-template name="Baz">
<xsl:with-param name="ParamA" select="$A" />
<xsl:with-param name="ParamB" select="$B" />
<xsl:with-param name="ParamC" select="$C" />
<xsl:with-param name="ParamD" select="$D" />
<xsl:with-param name="ParamE" select="$E" />
<xsl:with-param name="ParamF" select="$F" />
</xsl:call-template>
</a>
</xsl:when>
<xsl:otherwise>
<xsl:call-template name="Baz">
<xsl:with-param name="ParamA" select="$A" />
<xsl:with-param name="ParamB" select="$B" />
<xsl:with-param name="ParamC" select="$C" />
<xsl:with-param name="ParamD" select="$D" />
<xsl:with-param name="ParamE" select="$E" />
<xsl:with-param name="ParamF" select="$F" />
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
如您所见,
call-template
和传递的参数周围有很多重复的代码。有没有一种更整洁的、条件性嵌套元素的方式?
最佳答案
您可以在变量中调用模板,并将变量的结果放入choose中。