In-depth XSL (3)
--- Template rules and modes
Translation: Sun Yi
Template rules
Template rules are defined by the xsl: template element. The "match" attribute identifies the source node (SET) of the rule application. xsl: template. For example, an XML document may contain the following content:
This is an <emph> important </emph> point.
The following template rules match the elements of the emph type, and another template generates an fo: sequence format object, whose font-weight attribute is bold ).
<Xsl: template match = "emph">
<Fo: sequence font-weight = "bold">
<Xsl: process-children/>
</Fo: sequence>
</Xsl: template>
Xsl: the process-children element recursively processes the child nodes of the parent element.
Mode
A pattern is a string used to match an element in an XML source file. the most common pattern specifies the type name of the matching element. for example, the emph pattern matches elements of the emph type. the more complex pattern specifies the element type of the "ancestor" node of the matching element. for example, the olist/item pattern matches an element of the item type and the parent element is of the olist type. each element type in the "ancestor" sequence can be followed by a series of delimiters separated by commas. for example, list [attribute (ordered) = "yes")]/item [first-of-type ()] matches the element of the item type, the first element at the same level, the parent node type is list, and the attribute name "ordered" is "yes ".
This section describes the syntax and semantics of the pattern in detail. the pattern of matching elements is considered as match pattern ). xsl: The template pattern is the matching pattern. A mode can also be used to select a series of nodes. This mode is considered as select pattern ). in a selection mode, there is a current node to provide the frontend and backend relationships for selection. this mode selects a matched column of source nodes. these nodes are sorted by files. the modes in xsl: process, xsl: for-each and xsl: value-of are select modes.
------------------------------------------------------------------------------