Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between 'xsl:copy-of' and 'xsl:sequence'?

Tags:

xml

xslt

What is the difference between 'xsl:copy-of' and 'xsl:sequence'

like image 717
Pravesh Kumar Avatar asked Sep 03 '25 14:09

Pravesh Kumar


1 Answers

In very many situations they are interchangeable. One difference is that xsl:copy-of has more options (validation, copy-namespaces, etc). But most of the time you could use either.

There is a formal difference in that xsl:copy-of creates new nodes, while xsl:sequence returns a reference to existing nodes. That matters if, for example you use the "is" operator on the result, or if you use generate-id(), or if you navigate outside the subtree (e.g. to the parent of the copied node).

It's fair to say that 90% of the time people use xsl:copy-of in preference to xsl:sequence because that's what you did in XSLT 1.0, not because they really want a copy made.

like image 60
Michael Kay Avatar answered Sep 05 '25 08:09

Michael Kay