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 O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.