Default Template Values

As I mentioned earlier, if you give a parameter a value when you declare it, that value can be overridden if you specify a different value in an <xsl:with-param> element. However, if you don’t specify a different value, the original value acts like a default value.

The following example adapts the earlier “COLORS” example. That template has a parameter named COLOR, but I can call this template without setting COLOR to any particular value:

 <xsl:template match="PLANET"> <xsl:if test="NAME='Mercury'"> <xsl:call-template name="COLORS"> <xsl:with-param name="COLOR" select="'RED'"/> </xsl:call-template> </xsl:if> <xsl:if test="NAME='Venus'"> <xsl:call-template name="COLORS"> <xsl:with-param name="COLOR" select="'GREEN'"/> ...

Get Inside XSLT now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.