Blog Stats
  • Posts - 42
  • Articles - 0
  • Comments - 61
  • Trackbacks - 36

 

XSLT lessons #1

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="."/>

xsl:if>

<xsl:apply-templates mode="EmpIncome" select="."/>

xsl:for-each>

 

Definition of the template:

==========================================================

<xsl:template match="EmpHistory/EmpDetails[@type='EmpDetails']" mode="EmpAddress">

.......one way of implementation (some nodes, some elements)......

xsl:template>

<xsl:template match="EmpHistory/EmpDetails[@type='EmpDetails']" mode="EmpIncome">

.......another way of implementation (some other nodes, some other elements)......

xsl:template>


Feedback

No comments posted yet.


Post a comment





 

 

 

Copyright © Vinayak