Top-Level Elements

To this point, we haven’t actually talked about our source document or how we’re going to transform it. We’re simply setting up some properties for the transform. There are other elements we can put at the start of our stylesheet. Any element whose parent is the <xsl:stylesheet> element is called a top-level element. Here is a brief discussion of the other top-level elements:

<xsl:include> and <xsl:import>

These elements refer to another stylesheet. The other stylesheet and all of its contents are included in the current stylesheet. The main difference between <xsl:import> and <xsl:include> is that a template, variable, or anything else imported with <xsl:import> has a lower priority than the things in the current stylesheet. This gives you a mechanism to subclass stylesheets, if you want to think about this from an object-oriented point of view. You can import another stylesheet that contains common templates, but any templates in the importing stylesheet will be used instead of any templates in the imported stylesheet. Another difference is that <xsl:import> can only appear at the beginning of a stylesheet, while <xsl:include> can appear anywhere.

<xsl:strip-space> and <xsl:preserve-space>

These elements contain a space-separated list of elements from which whitespace should be removed or preserved in the output. To define these elements globally, use <xsl:strip-space elements="*"/> or <xsl:preserve-space elements="*"/>. If we want to specify that whitespace be ...

Get XSLT, 2nd 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.