skip to navigation
skip to content

XSLClearer 0.1.3

XSLClearer makes writing XSL template easier to write.


XSLClearer tries to make writing XSL templates easier.

It is a proof of concept. It is therefore in early stage of development.
Though it works on a simple example, it will surely fail at more concrete

It is in fact a very crude compiler (lexical+grammar).



The xsls format converts:

tag(attribute="value", attribute="value") {
tag(attribute="value", attribute="value");

tag(attribute="value") {


<xsl:tag attribute="value" attribute="value">
<xsl:tag attribute="value" attribute="value"/>

<xsl:tag attribute="value">

XSLClearer recognizes tags and attributes up to XSLT 3.0. A tag/attribute
without a preceding namespace must be and XSLT 3.0 or XSLT-FO tag/attribute.
It otherwise throw an error. If there is a preceding namespace, no check is

If you need to use a closing bracket inside the [ ], you may escape it using
the back-slash.

If you need to use a double quote inside the " ", you may escape it using
the back-slash.


The xsls format converts:

$variable = "string";


<xsl:variable name="variable" select="string"/>

The xsls format converts:

$variable = {


<xsl:variable name="variable">


Strings are enclosed with double quotes ("). It accepts \ as an escaping
character (\\ to insert \, \" to insert " inside a string).

Special XML characters are automatically escaped.


"string-length(\"abc\") > 2"

translates into:

"string-length("abc") > 2"

CSS selector strings

Strings can contain CSS selector if they are directly preceded by a #.


#"ns|tag ns|tag#identifier"

translates into:


It uses the **cssselect** Python module to do the conversion.

If this module is missing, xslclearer raises an exception.

Tags with only one attribute

The xsls format converts:

call-template("string") {


<xsl:call-template name="string">

It works for the following tags (attribute):

* when (test),
* if (test),
* for-each (select),
* call-template (name),
* include (href),
* import (href),
* copy (use-attribute-sets),
* copy-of (select),
* message (terminate),
* preserve-space (elements),
* strip-space (elements),
* text (disable-output-escaping).

Though they may have more than one attribute, it also works for the following
tags (attribute):

* value-of (select),
* apply-templates (select),
* template (name),
* attribute (name).

In this case, the argument must be given at the very first position.


template("template-name", match="*") {

translates into:

<xsl:template name="template-name" match="*">

Tag and attribute verification

The compiler verifies that identifiers are from the XSL or XSL-FO tags lists.
Specifying a namespace disables the verification.

The verification alsa applies to the attributes.


Just place the in a directory pointed to by the PATH variable
environment, make it executable and that’s all !

If you want syntax highlighting in gedit, you can copy the xsls.lang file to
the /usr/share/gtksourceview-3.0/language-specs directory (adjust it
accordingly to your configuration).


XSLClearer has been developped with Python 3.

It only requires the re and sys modules.


python3 input.xsls > output.xslt

cat input.xsls | python3 > output.xslt

xslsproc style.xsls input.xml > output

The xslsproc is a wrapper for the xsltproc command. It analyzes the options to
find the an xsls file. If it can be found, the file is transparently converted
to an xslt stylesheet and feed to xsltproc. Every other option is passed
without any change. You can therefore use xslsproc exactly like you would use
xsltproc except it understands xsls files and not xslt files.


The example directory contains an example of an XSL template converted to XSLS
and a file called menu.xml on which the template works.  
File Type Py Version Uploaded on Size
XSLClearer-0.1.3.tar.gz (md5) Source 2014-06-11 13KB