I am reading a book on XSLT 2.0. I am on the chapter of XSLT Result Trees. Frankly, i don't understand it a bit. What are result trees? What is it used for? Why is it important?
XML documents form trees. A result tree is simply the name for the new tree you create after running an XSL transformation on a source tree: "A transformation expressed in XSLT describes rules for transforming zero or more source trees into one or more result trees" (from W3C).
From the W3C XSLT 2.0 Specification:
"[Definition: The term result tree is used to refer to any tree constructed by instructions in the stylesheet. A result tree is either a final result tree or a temporary tree.]
[Definition: A final result tree is a result tree that forms part of the final output of a transformation. Once created, the contents of a final result tree are not accessible within the stylesheet itself.] The xsl:result-document instruction always creates a final result tree, and a final result tree may also be created implicitly by the initial template."
This means that all output from the XSLT transformation is a set of result trees (this will be a single result tree if no <xsl:result-document>
is used).
Also, any temporary tree like one created in the body of an <xsl:variable>
(that isn't produced as a separate output, but is used internally in the course of the transformation) is a result tree.
It is important to know that any XSLT transformation operates on trees and the result of the transformation is also a set of trees.