Multiple Matches with |
You often want to match more than one type of element or
attribute but not all types. For example, you may want an XSLT
template that applies to the profession and hobby elements but not to the name, person, or people elements. You can combine
location paths and steps with the vertical bar (|) to indicate that you want to match any
of the named elements. For instance, profession|hobby matches profession and hobby elements. first_name|middle_initial|last_name
matches first_name, middle_initial, and last_name elements. @id|@xlink:type matches id and xlink:type attributes. *|@* matches elements and attributes but
does not match text nodes, comment nodes, or processing-instruction
nodes. For example, this XSLT template rule applies to all the
nonempty leaf elements (elements that don’t contain any other
elements) of Example 9-1of Example 9-1:
<xsl:template match="first_name|last_name|profession|hobby"> <xsl:value-of select="text( )"/> </xsl:template>
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access