Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>What makes you think that procedural terms do not apply here? It's just that the calling convention is somewhat more implicit than you would traditionally expect it, because there is an invisible context involved. Everything <code>apply-templates</code> does could be expressed in procedural terms.</p> <p>Basically, <code>apply-templates</code> is nothing more than a for-each loop. Starting from where where you currently are in the document (the context, think "<code>this</code>"), it iterates over the child nodes. </p> <p>For each child, the processor selects the matching <code>xsl:template</code> with the highest priority (based on their respective <code>match</code> and <code>priority</code> attributes), sets the context to the child at hand and runs this template (think "<code>function</code>"). After the template returns, the context snaps back and it's the next child's turn.</p> <p>Even when things become recursive (which is somewhat hard to avoid in XSLT), the whole process really does not become any more complicated. The context "pointer" is moved around, and templates get called.</p> <p>You can restrict the node set that <code>apply-templates</code> iterates over, using the <code>select</code> attribute:</p> <pre><code>&lt;!-- all children of the context node regardless --&gt; &lt;xsl:apply-templates /&gt; &lt;!-- all children of the context node being "data" with a @name of "Foo" --&gt; &lt;xsl:apply-templates select="data[@name='Foo']" /&gt; </code></pre> <p>You can sort the node-set prior to the iteration, if you wish:</p> <pre><code>&lt;!-- all children of the context node being "data" with a @name of "Foo", ordered by their respective "detail" count --&gt; &lt;xsl:apply-templates select="data[@name='Foo']"&gt; &lt;xsl:sort select="count(detail)" data-type="number" order="descending"/&gt; &lt;/xsl:apply-templates&gt; </code></pre> <p>And you can pass parameters to your template if you need, just like you would with a regular function call:</p> <pre><code>&lt;!-- pass in some parameter --&gt; &lt;xsl:apply-templates select="data[@name='Foo']"&gt; &lt;xsl:with-param name="DateSetIcon" select="$img_src" /&gt; &lt;/xsl:apply-templates&gt; </code></pre> <p>That's about all there is to it.</p> <p>EDIT:</p> <p>I know that the last comment is a bit provocative. This is very much intentional, for a basic understanding of how <code>apply-templates</code> works this is more or less it. The implications and possibilities that come from the fact that not <em>you</em> are defining what template to call, but rather let the processor choose the right one for you are of course bigger than what it sounds like to the untrained ear. The declarative/implicit approach of the whole thing surely needs some time to sink in.</p>
    singulars
    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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. 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