Introduction

Rexsel provides a clean, easily understandable means of writing XSLT scripts without having the extra "baggage" of XML syntax. It allows the actual mechanism of the script to be grasped more easily. It does nothing other than provide a different means of producing XSLT, in particular it does not replace supporting languages used by XSLT such as XQuery.

To illustrate the language, consider a simple XSLT stylesheet that defines a (recursive) function that outputs, or returns, a string after the last occurrence of a specified delimiter within a given string.

<?xml version="1.0" encoding="UTF-8"?> <stylesheet xmlns="http://www.w3.org/1999/XSL/Transform" version="1.0"> <template name="substring-after-last"> <param name="string"/> <param name="delimiter"/> <choose> <when test="contains($string, $delimiter)"> <call-template name="substring-after-last"> <with-param name="string" select="substring-after($string, $delimiter)"/> <with-param name="delimiter" select="$delimiter"/> </call-template> </when> <otherwise> <value-of select="$string"/> </otherwise> </choose> </template> </stylesheet>

Even with a good understanding of XML and XSLT, it can be difficult for a newcomer to XSLT to see the operation of this function (especially so with bigger functions than this). One particular aspect is the use of the tag <xsl:template ...> which is used to define both functions and matches, albeit with different attributes: name and match respectively.

Rexsel attempts to make this clearer so the XSLT function above can be written as

stylesheet { version "1.0" proc substring-after-last { parameter string parameter delimiter choose { when "contains($string, $delimiter)" { call substring-after-last { with string "substring-after($string, $delimiter)" with delimiter "$delimiter" } } otherwise { value "$string" } } } }

The keyword proc denotes function to prevent confusion with the same keyword in XSLT3 and later that uses the function keyword elsewhere. The choice of proc shows the author's past life when using Algol-68.

Copyright 2024 Hugh Field-Richards. All Rights Reserved.