How Does Component Visibility Work in XSLT 3.0?

XSLT 3.0 introduces a modular packaging system via xsl:package that allows stylesheets to encapsulate code, prevent naming collisions, and control external access to their internal definitions. Component visibility determines whether components—such as templates, functions, variables, modes, keys, and attribute sets—can be referenced, overridden, or extended by importing stylesheets. By assigning visibility levels such as public, private, final, and abstract, developers can enforce strict interface contracts and maintain clean separation of concerns across complex transformation pipelines.

The Role of Packages in XSLT 3.0

Prior to XSLT 3.0, modularity relied on xsl:include and xsl:import, which merge declarations into a single flat namespace where global variables and templates can unintentionally collide.

An XSLT 3.0 package (<xsl:package>) operates as an independent compilation unit. Declarations within a package interact through well-defined interfaces. When a stylesheet imports a package using <xsl:use-package>, it can only see components explicitly exposed by that package. Visibility controls access boundaries both within the declaring package and across consuming packages.

The Core Visibility Levels

The visibility attribute can be applied directly to components or set as a default on <xsl:package>. The four primary visibility values function as follows:

1. private

A private component is strictly internal to the declaring package.

2. public

A public component forms part of the package’s exposed interface.

3. final

A final component is visible externally but cannot be modified.

4. abstract

An abstract component defines a required contract without providing an implementation in the declaring package.

Modifying Visibility with xsl:use-package

When a package consumes another package using <xsl:use-package>, it can alter the exposed components' visibility using child elements:

Supported Declarations

Visibility attributes are supported across major top-level XSLT declarations:

By leveraging explicit visibility semantics, XSLT 3.0 packages enable true encapsulation, reusable component libraries, and safe, compile-time verified transformations.