In
<xsl:template name="temp_name" mode="mode">
What is the meaning of mode
? I searched many many resource, but i couldn't find example for that. So can anybody explain with an example? Thanks in advance.
In
<xsl:template name="temp_name" mode="mode">
What is the meaning of mode
? I searched many many resource, but i couldn't find example for that. So can anybody explain with an example? Thanks in advance.
It isn't too meaningful to give a template both a name and a mode.
The
name
attribute fully identifies a template and there cannot be two templates with the same name and different modes.The
mode
attribute allows the same nodes to be processed more than once, using different modes.Here is a short example:
When this transformation is applied on the following XML document:
The result is that the numbers are displayed in three
tr
(rows), each containing three columns (with the possible exception of the last row):In this transformation, any
num
element with position that cannot be represented in the form3*k +1
(wherek
is an integer), is matched by a template with empty body and thus isn't processed.However, we want to process all
num
elements that should form the cells of a row. For this purpuse, we are processing them using the xslt instruction:which means: "Do not apply to the selected nodes templates that would normally be applied (in no mode), but apply templates that are in
copy
mode"Thus, we do not ignore the selected
num
elements, but are processing them incopy
mode and are creating thetd
s of a row.The template rule:
is necessary to override the xslt builtin templates (default processing) that would otherwise cause the string values of the
num
nodes whose position cannot be represented as3*k +1
, to be output.So, these nodes are processed by both templates:
and
and thus we get the wanted result.
It would be instructive to step through with a good XSLT debugger in order to see how these templates are applied.
Link a simple example here: https://msdn.microsoft.com/en-us/library/ms256045%28v=vs.110%29.aspx