Reputation: 103388
I have an XSLT template which conditionally needs nesting in an anchor
element.
For example:
<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>
As you can see, theres a lot of duplicate code here around the call-template
and the parameters passed.
Is there a tidier, DRYer, way of conditionally nesting elements?
Upvotes: 2
Views: 70
Reputation: 117100
You could call the template in a variable, and place the result of the variable inside the choose.
Upvotes: 2