Templates

Template element

Templates are defined by the Template element.

<!ELEMENT xsl:template (#PCDATA %instructions;
                        %result-elements; | xsl:param)* >

The keyword '#PCDATA' refers to text that can be inserted directly into the Template element:

<xsl:template ...>REPLACE WITH THIS</xsl:template>

A template can also contain various instruction elements. Apart from the Param element, and the content of the Result Elements entity (described later), the Instructions entity is used to group the instruction elements, because they are also allowed in other locations (the For Each element and the Template entity):

<!ENTITY % instructions " %char-instructions; |
                          xsl:processing-instruction |
                          xsl:comment |
                          xsl:element |
                          xsl:attribute">

This entity encompasses all XSLT instructions. However, most of the instructions allowed are further referenced from another entity, called Character Instructions:

<!ENTITY % char-instructions " |
                 xsl:apply-templates | xsl:call-template |
                 xsl:apply-imports | xsl:for-each |
                 xsl:value-of | xsl:copy-of |
                 xsl:number | xsl:choose | xsl:if |
                 xsl:text | xsl:copy | xsl:variable |
                 xsl:message | xsl:fallback">

This is done because these instructions are also referenced from another entity. The Char Template entity also uses this entity, and is in turn referenced from the Processing Instruction, Comment and Attribute element definitions:

<!ENTITY % char-template "
                 ( #PCDATA  %char-instructions; ) ">


<!ELEMENT xsl:comment                (%char-template;)>

<!ELEMENT xsl:processing-instruction (%char-template;)>

<!ELEMENT xsl:attribute              (%char-template;)>

The reason for splitting the instructions in this way is to avoid the possibility of some elements containing other elements, such as comments containing either comments or processing instructions (which would be illegal). Character instructions are therefore instructions that can contain characters and further instructions.

Attributes

The XSLT attributes specified for the Template elements are as follows:

<!ATTLIST xsl:template
                match      %pattern;    #IMPLIED
                name       %qname;      #IMPLIED
                priority   %priority;   #IMPLIED
                mode       %qname;      #IMPLIED
                %space-att;>

With all the embedded entity references replaced, the true model is as follows:

<!ELEMENT xsl:template
                match      CDATA              #IMPLIED
                name       NMTOKEN            #IMPLIED
                priority   NMTOKEN            #IMPLIED
                mode       NMTOKEN            #IMPLIED
                xml:space (default|preserve)  #IMPLIED >

For example:

<xsl:template match="title" priority="2"
              mode="SpecialMode" >...</xsl:template>

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset