Chapter 12. XSLT Patterns
A pattern is used in XSLT to define a condition that a node must satisfy in order to be selected. The most common use of patterns is in the match
attribute of <xsl:template>
, where the pattern says which nodes the template rule applies to. For example, <xsl:template match ="abstract"
introduces a template rule that matches every <abstract>
element. This chapter defines the syntax and meaning of XSLT patterns.
Patterns (sometimes called match patterns) are used in just six places in an XSLT stylesheet:
In the
match
attribute of<xsl:template>
, to define the nodes in a source document to which a template appliesIn the
match
attribute of<xsl:key>
, to define the nodes in a source document to which a key definition appliesIn the
count
andfrom
attributes of<xsl:number>
, to define which nodes are counted when generating numbersIn the
group-starting-with
andgroup-ending-with
attributes of<xsl:for-each-group>
, to identify a node that acts as the initial or final node in a group of related nodes
Patterns and Expressions
Most of the patterns found in stylesheets are simple and intuitive. For example:
Pattern | Meaning |
---|---|
| Matches any |
| Matches any |
| Matches any |
| Matches any |
The rules for the more complex patterns, ...
Get XSLT 2.0 and XPath 2.0 Programmer's Reference, 4th Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.