Skip to content

Reconciles xsl:import elements to create a single, consolidated, XSLT stylesheet

License

Notifications You must be signed in to change notification settings

cjungmann/xsl-import

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

xsl-import

xsl-import is a simple command-line tool, written in Python, that generates a single XSLT document from a XSLT document and its xsl:import references.

It is often desirable to split large code projects into several files to group related elements. It helps by increasing code readability, clarity, and modularity. This is particularly useful for XSLT stylesheets, whose language is verbose and more difficult to follow than most other computer languages. This tool enables a user to take advantage of the benefits of developing with multiple files while making it easy to deliver a single stylesheet. As a command-line tool, it can be incorporated into a Makefile to ensure the consolidated stylesheet is up-to-date.

Installation

$ git clone https://github.com/cjungmann/xsl-import.git

Installation contains the Python program, README.md and LICENSE files, and several simple stylesheets for testing the output. The Python source file can be moved or copied to an appropriate directory to make it universally accessible (ie /usr/bin/).

Usage

$ xsl-import [-is] _your-file.xsl_

-i will add an import source comment to each imported element.
-s will strip all comments from imported elements.

There are 4 sample XSLT files included with the project. Together, they test two levels of xsl:import (an imported file that itself includes a third file).

Run the test, including the import file comments to see how priorities are resolved:

$ xsl-import -i base.xsl

The strip comments flag, -s, is intended to generate a somewhat minimized document for delivery, especially over the web. This makes it more feasible to liberally document the XSLT files to help clarify what is otherwise a rather difficult computer language to scan.

The output can be a bit ragged. Linux users can take advantage of the command line utility xmllint (packaged with Rather than trying to make a pretty-print feature, it is recommended that (Linux) users take advantage of the xmllint tool for a cleaner looking file:

To install xmllint:

$ sudo apt-get install libxml2-utils
$ man xmllint

To use xmllint:

$ xsl-import -s base.xsl | xmllint --format -

Description

This command-line tool will read an XSLT file, and recursively incorporate unique element children of the document element xsl:stylesheet of files indicated with xsl:import elements.

The output will be the text of a single XSLT document that directly contains the unique elements of the imported files. Sending this file to an end-user instead of the set of files it represents will improve performance, particularly in a web-delivery system that would otherwise have many server round-trips to confirm the validity of each imported file.

Sending a single file also benefits users of Web-kit-based browsers, whose XSLProcessor object cannot handle xsl:import.

Limitations

Currently, this utility will only attempt to incorporate files referenced by xsl:import. This is because the location of the xsl:import element and the rules by which conflicts are resolved are stricly defined. xsl:include references will not be reconciled, and if used, these files must be made available for parsers to access.

Currently, comment block children of xsl:stylesheet from imported files are not transfered. The comments of the base file are not disturbed. The comments within imported elements are left in place unless the -s (strip comment) flag is used.

Future Possibilities

There is no plan to support reconciling xsl:include references unless there is expressed interest.

About

Reconciles xsl:import elements to create a single, consolidated, XSLT stylesheet

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published