<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''/>
</xsl:call-template>
</xsl:if>
<xsl:if test='NAME='Earth''>
<xsl:call-template name='COLORS'>
<xsl:with-param name='COLOR' select=''BLUE''/>
</xsl:call-template>
</xsl:if>
</xsl:template>
.
.
.
Данная таблица вызывает шаблон «COLORS» с разными значениями параметра COLOR. Я могу воспользоваться этими цветами при форматировании данных планет. Заметьте, что я объявил параметр COLOR при помощи <xsl:param>
в самом начале шаблона «COLORS»:
<xsl:stylesheet version='1.1'
xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>
<xsl:template match='/PLANETS'>
<HTML>
.
.
.
</HTML>
</xsl:template>
<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''/>
</xsl:call-template>
</xsl:if>
<xsl:if test='NAME='Earth''>
<xsl:call-template name='COLORS'>
<xsl:with-param name='COLOR' select=''BLUE''/>
</xsl:call-template>
</xsl:if>
</xsl:template>
<xsl:template name='COLORS'> <xsl:param name='COLOR'/>
<TR>
<TD>
<FONT COLOR='{$COLOR}'><xsl:value-of select='NAME'/></FONT>
</TD>
<TD>
<FONT COLOR='{$COLOR}'><xsl:apply-templates select='MASS'/></FONT>
</TD>
<TD>
<FONT COLOR='{$COLOR}'><xsl:apply-templates select='RADIUS'/></FONT>
</TD>
<TD>
<FONT COLOR='{$COLOR}'><xsl:apply-templates select='DAY'/></FONT>
</TD>
</TR>
</xsl:template>
<xsl:template match='MASS'>
<xsl:value-of select='.'/>
<xsl:text> </xsl:text>
<xsl:value-of select='@UNITS'/>
</xsl:template>
.
.
.
<xsl:template match='DAY'>
<xsl:value-of select='.'/>
<xsl:text> </xsl:text>
<xsl:value-of select='@UNITS'/>
</xsl:template>
</xsl:stylesheet>
И вот результат:
<HTML>
<HEAD>
<TITLE>
The Colorful Planets Table
</TITLE>
</HEAD>
<BODY>
<H1>
The Colorful Planets Table
</H1>