Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I strongly agree with the answer and blog post of Greg Beech.</p> <p>For more detailed comparison between <code>&lt;xsl:for-each&gt;</code> and <code>&lt;xsl:apply-templates&gt;</code> see <a href="http://markmail.org/message/xbm7tsglnhqogdzd" rel="nofollow noreferrer"><strong>my answer</strong></a> to the question "xsl:for-each vs. xsl:apply-templates" in the xsl-list, and enjoy <a href="http://markmail.org/message/xbm7tsglnhqogdzd#query:+page:1+mid:u6vldphwj263tejm+state:results" rel="nofollow noreferrer"><strong>the whole thread</strong></a>.</p> <p>"<em>xsl:apply-templates is much richer and deeper than xsl:for-each, even simply because we don't know what code will be applied on the nodes of the selection -- in the general case this code will be different for different nodes of the node-list. <strong>Also, the code that will be applied can be written way after the xsl:apply templates was written and by people that do not know the original author</em></strong>".</p> <p>Another difference from a procedural programming language is that the order in which the templates will be applied is not predefined. There is no notion of "state" or "order of execution" in a pure functional programming language. </p> <p>Neither <a href="http://www.w3.org/TR/xslt20/#applying-templates" rel="nofollow noreferrer"><strong>XSLT 2.0</strong></a> nor <a href="http://www.w3.org/TR/xslt#section-Processing-Model" rel="nofollow noreferrer"><strong>XSLT 1.0</strong></a> specifies any particular order of applying the selected template rules -- only that their results will be combined according to the order of the nodes (in the sorted sequence, if there are any <code>&lt;xsl:sort&gt;</code> directives or otherwise in the document order of the nodes), on which the templates are applied.</p> <p>The <a href="http://www.w3.org/TR/xslt20/#applying-templates" rel="nofollow noreferrer"><strong>XSLT 2.0 Spec</strong></a> says:</p> <p>"<em>Each template rule that is evaluated produces a sequence of items as its result. The resulting sequences (one for each node in the sorted sequence) are then concatenated, to form a single sequence. They are concatenated retaining the order of the nodes in the sorted sequence. The final concatenated sequence forms the result of the xsl:apply-templates instruction</em>"</p> <p>The <a href="http://www.w3.org/TR/xslt#section-Processing-Model" rel="nofollow noreferrer"><strong>XSLT 1.0</strong></a> spec says:</p> <p>"<em>Implementations are free to process the source document in any way that produces the same result as if it were processed using this processing model</em>."</p> <p>It is even possible that an XSLT implementation may apply templates (or the body of an <code>&lt;xsl:for-each&gt;</code>) in parallel.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload