Pattern-based Templates
The template rules shown so far in this chapter have been named and invoked based on a symbolic name. XSLT also supports invoking template rules based on pattern-matching. An XSLT pattern is a stylized XPath expression that identifies subsets of the source document. An XSLT pattern contains one or more location paths separated by a |. Location paths contained in XSLT patterns can only use the child and attribute axes. That stated, a location path in an XSLT pattern can use also the // operator (but not the equivalent descendant-or-self axis).
Patterns are associated with a template rule using the match attribute instead of the name. attribute.
<xsl:template match='author|illustrator' > <contributor /> </xsl:template> ...
Get Essential XML: Beyond Markup 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.