Many of us often forget things we've learnt over a period of time, if we do not make a special note of them. Its been more than 4 years now that I've been savouring XSLT and XML continuously in whichever project I work on. I've learnt quite a lot tricks of trade though they look minuscule. Thought would put them in here, as and when I remember them. Here's one to start with.
1. Whenever we want to apply-templates for the same set of nodes with two different templates for two different set of implementations, always use the “mode” attribute while calling as well as defining them.
Example :
The template call:
==========================================================
<
xsl:for-each select="EmpHistory/EmpDetails[@type='EmpDetails']">
<xsl:if test="position() = $currposn+1 or position() = $prevposn+1">
<xsl:apply-templates mode="EmpAddress" select="."/>
< FONT>xsl:if>
<xsl:apply-templates mode="EmpIncome" select="."/>
< FONT>xsl:for-each>
Definition of the template:
==========================================================
<
xsl:template match="EmpHistory/EmpDetails[@type='EmpDetails']" mode="EmpAddress">
.......one way of implementation (some nodes, some elements)......
< FONT>xsl:template>
<
xsl:template match="EmpHistory/EmpDetails[@type='EmpDetails']" mode="EmpIncome">
.......another way of implementation (some other nodes, some other elements)......
< FONT>xsl:template>