[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

RE: [xsl] Re: Benefits of xsl.sequence


Subject: RE: [xsl] Re: Benefits of xsl.sequence
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Tue, 30 Sep 2008 09:58:24 +0100

> Could the use of xsl:sequence be considered mostly an 
> uptimization issue? A lot of the functionality of 
> xsl:sequence is covered by xsl:copy-of, and we can make 
> sequences in e.g. variables directly like xsl:variable 
> name=x" select="(2, 5, 8)"/>?

If you're using atomic values, then xsl:copy-of and xsl:sequence produce the
same run-time effect. However, if the system doesn't know statically that
the input will be atomic values rather than nodes, then more code might be
generated for the xsl:copy-of case, because it is a more complex
instruction. (xsl:sequence is essentially a no-op - it's just a syntax
wrapper that presents an XPath expression as an XSLT instruction.) Also,
because xsl:copy-of has the potential to create new nodes, it can't be
optimized away quite as easily as xsl:sequence; for example a call to a
function that calls xsl:copy-of can't safely be moved out of a loop.

> 
> Is there anything in XSLT 2.0 we can only do using xsl:sequence?
> 

Yes: this is the only way that you can write a function (or indeed a
template) that returns references to existing nodes, as distinct from newly
constructed nodes. That's very important if you're doing graph-manipulation
operations like checking your data for cycles.

Michael Kay
http://www.saxonica.com/


Current Thread
Keywords