Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Agreed to both answers so far; your assessment that Template #2 won't get processed as such is exactly right.</p> <p>Note that a node's children (i.e. its child elements, comments, text, and processing instructions, but <em>not</em> attributes) are only special in two ways:</p> <ol> <li>The default value of the <code>select</code> attribute is "<code>node()</code>", the XPath for selecting children, and</li> <li>The built-in template rules for root nodes and element nodes is to process children.</li> </ol> <p>Other than in those two respects, children have no special status when it comes to selecting nodes to process. You can select whatever nodes you want, including ancestors. You can traverse a tree in any order you like. An extreme way to demonstrate this would be to write a stylesheet that reverses the hierarchy of a document (turns it upside down). (You'd probably want to use another mode so that a different rule is invoked when parent nodes are processed than when children are processed.)</p> <p>I also want to check and make sure you understand the distinction between the "root node" (renamed the "document node" in XPath/XSLT 2.0) and the root (or document) <em>element</em>. In your example XML, &lt;person> is <em>not</em> the root node; it's the outermost <em>element</em>, which itself is a child of the root node, the invisible outer container at the root of every tree in the XPath/XSLT data model.</p> <p>If you want to take control of processing right of the bat, you can always use &lt;xsl:template match="/"> or (assuming the source tree represents a well-formed XML document and not a fragment) &lt;xsl:template match="/*">. They're alternative ways to do it. One feature of the latter is that imported code that includes a rule for match="/" would be triggered earlier, since explicit template rules (even if they have the lowest import precedence) always take precedence over built-in template rules. If you don't explicitly have &lt;xsl:template match="/"> in the importing stylesheet, then, until you import code that has it, you're relying on the built-in template rule for root nodes (apply templates to children--in this case, apply templates to the &lt;person> element child).</p> <p>An alternative way to take control off the bat, for this example, would be to use match="/person". Such a rule would match any &lt;person> element, provided that it's the child of the root node. If the XML doesn't have &lt;person> as its outermost element, then it won't get invoked. And if you also have &lt;xsl:template match="/", then it would get invoked first; the match="/person" (or match="/*") would only get invoked if the match="/" rule explicitly applied templates to children.</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. 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.
    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