How to create an XSLT template

This is the second post in my flash post series on XSLT. We'll start off with some simple examples and move up to advanced as we get the most important components in place.

   1:  <-- The most basic thing you should know about is how to create and call a template. 
   2:  A template is a procedure that is executed when a certain criteria is met. 
   3:  That we will come back to.
   4:   -->
   5:   
   6:  <!-- First off is the template. A template is the most basic element in an XSLT sheet.
   7:  This perticular template targets the XML root node, but gives no output.-->
   8:   
   9:    <xsl:template match="/">
  10:    </xsl:template>
  11:   
  12:  <!-- The following template targets any node and attribute, 
  13:  but gives no output.-->
  14:   
  15:      <xsl:template match="@* | node()">
  16:      </xsl:template>
  17:    
  18:  <!--Now, for the first two, they are executed no matter how the source is structured. 
  19:  The next two act a little differently. While the one matching "title" is executed 
  20:  whenever the engine finds a title node, the template named "mySpecialTemplate" 
  21:  is executed ONLY when called. For this example I'm basically calling it from 
  22:  inside the first template to show how it is done. A template can be called from 
  23:  inside any template at any time.-->
  24:    
  25:  <!-- This template targets all nodes of the type title -->
  26:   
  27:      <xsl:template match="title">
  28:          <xsl:call-template name="mySpecialTemplate" />
  29:      </xsl:template>
  30:    
  31:  <!-- This template has a name and is executed on command -->
  32:   
  33:      <xsl:template name="mySpecialTemplate">
  34:      </xsl:template>


Comments

Popular posts from this blog

Designing and programming - Part 2

Filtering Dropdown choices in a Power Pages form using Dataverse Relations

Exploring the Power of Variables in Liquid and Power Pages