import/include

The import and import statements only occurs at the root level of the stylesheet and used to combine the contents of another stylesheet into the currently declared sheet.

The include statement is similar to include statements in other languages, allowing the inclusion of other stylesheets without interfering with the action of the parent stylesheet.

The import statement is similar to the include statements except that it the templates (proc and match) in the importing stylesheet take precedence over template rules and definitions in the imported stylesheet.

Syntax
<import> ::= ( "import" | "include" ) <quote> <uri> <quote>
Options
uri The URI of the include file.
Elements

None.

Examples

Using an example in the W3C specification one stylesheet could import sheet doc.xsl and modify the treatment of example <elements> as follows:

stylesheet { version "1.0" import "doc.xsl" match using "example" scope "example-1" { element "div" { attribute "style" "border: solid red" apply-imports } } }

would give the following XSLT

<?xml version="1.0" encoding="UTF-8"?> <stylesheet xmlns="http://www.w3.org/1999/XSL/Transform" version="1.0"> <import href="doc.xsl"/> <template match="example" mode="example-1"> <element name="div"> <attribute name="style"> <text>border: solid red</text> </attribute> <apply-imports/> </element> </template> </stylesheet>
Errors

The only error here (until URI checking is added) is a missing URI reference.

stylesheet { version "1.0" import match using "example" scope "example-1" { element "div" { attribute "style" "border: solid red" apply-imports } } }

would report

**** (126) Missing URI, found 'match' in line 4 Insert URI.
Copyright 2024 Hugh Field-Richards. All Rights Reserved.