When should I use <copy-of>
instead of <apply-templates>
?
What is their unique role? Most of the time replacing <apply-templates>
with <copy-of>
gives out weird output. Why is that?
When should I use <copy-of>
instead of <apply-templates>
?
What is their unique role? Most of the time replacing <apply-templates>
with <copy-of>
gives out weird output. Why is that?
will simply return you a dump of the XML in the supplied node-set
on the other hand will apply any templates applicable to the node-set passed it.
xsl:copy-of
is an exact copy of the matched input xml element. No xslt processing takes place and the output from that element will be exactly the same as the input.xsl:apply-templates
tells the xslt engine to process templates that match the selected elements.xsl:apply-templates
is what gives xslt its overriding capability, since the templates you create with match on elements can have different priorities, and the template with the highest priority will be executed.Input:
Xslt 1:
Xml output 1:
Xslt 2:
Xml output 2: