RE: [xsl] More addition questions: Using node-set()

Subject: RE: [xsl] More addition questions: Using node-set()
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Thu, 11 Oct 2007 15:36:23 +0100
> E.g., if I get a result fragment tree(by doing something like 
> //a meaning get all the elements that are needed),

The expression //a returns a node-set. You will only get a result tree
fragment if you construct one by copying the elements, for example

<xsl:variable name="x">
  <xsl:copy-of select="//a"/>
</xsl:variable>

 convert it to a
> node-set() and then use it, and I do this 2-3 times for 
> different problem sets in say the same template, isn't there 
> a lot of redunancy going on?

It depends on the processor. In some processors the xx:node-set() function
is essentially a no-op, all it does it signal to the processor that you
don't want it to enforce the restrictions on use of result tree fragments.

However, you should avoid copying nodes when you don't need to. Many people
make the mistake of using variables-that-create-trees, like the above, when
they could and should be using variables-that-select-nodes, like
<xsl:variable select="//a"/>.

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

Current Thread