Modes: Context-Specific Formatting

Sometimes, matching nodes can be an art. For example, a template that matches “*” also matches “PLANET”. However, if you want <PLANET> elements handled differently than all other elements, you can set up a template that matches “PLANET”; the XSLT processor, knowing “PLANET” is a closer match to a <PLANET> element than “*”, uses the “PLANET” match. On the other hand, sometimes things aren’t so clear. For example, you may want “PLANETS” to match some <PLANET> elements, but not others. One way of making sure that happens is to use modes.

You can use the mode attribute of <xsl:apply-templates>to set a processing mode. When you set a mode, the only templates that match are those <xsl:template> elements that have ...

Get Inside XSLT 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.