XSLT/Rexsel Comparisons

Most of the Rexsel syntax uses familiar keywords that have a direct analogue within XSLT. However, there are certain restrictions and enhancements which, while not onerous, must be borne in mind when writing Rexsel stylesheets.

Templates

Templates in XSLT can be either a named or pattern match template. The former is effectively a procedure/macro that can be called from elsewhere in the stylesheet, while match is a means of matching the input against a pattern. Rexsel explicitly distinguishes between these two types by using different keywords: 'proc' and 'match'.

Having a distinction between 'proc' and 'match' ensures that there is never confusion and fulfils the requirement that the 'name' and 'match' attributes should never occur together in a <xsl:template> tag.

As an example, the 'match' below matches the input against the XPath 'p' within the scope (mode) of inline-text.

match using "p" scope "inline-text" { variable extra "'normalPara'" element "para" { apply-templates scope "inline-text" } }

This would translate to

<template match="p" mode="inline-text"> <variable name="extra" select="'normalPara'"/> <element name="para"> <apply-templates mode="inline-text"/> </element> </template>

Procedures are simpler

proc common.substring-after-last { parameter string parameter delimiter ... }

would translate to

<template name="common.substring-after-last"> <param name="string"/> <param name="delimiter"/> ... </template>

This proc could be called as

call common.substring-after-last { with string "Some text" with delimiter "," }

As an aside, note the use of names and string above. In general items that will appear in the output after XSLT processing is held within quote marks, while items such as proc names that are used by the XSLT processor do not.

Scope/Mode

Within 'match' templates there is concept of mode which defines a context or scope for that match (see example above). Rexsel uses the 'scope' keyword which, I believe, more accurately describes the concept.

Text Strings

When describing text strings it is important to "escape" control characters such as '\'.

Required Entered \ \\ < &lt; > &gt; " \" When occuring in double quoted strings ' \' When occuring in single quoted strings

When not a simple piece of text, such as in 'attribute', text must be entered using the 'text' keyword. For example

<xsl:template name="begin-documentation-section"> \nwbegindocs{<xsl:value-of select="position() - 1"/>} </xsl:template>

would have to be written as

proc begin-documentation-section { text "\nwbegindocs{" value "position() - 1 " text "}" }

or as

proc begin-documentation-section { value "concat( '\nwbegindocs{', position() - 1, '}' )" }
Raw Non-XSLT

Rexsel does not allow "naked" non-XSLT elements. For example if the XSLT contained

<xsl:template match="example"> <div style="border: solid red"> <xsl:apply-imports/> </div> </xsl:template>

this would have to be written in Rexsel as

match using "example" { element "div" { attribute "style" "border: solid red" apply-imports } }
Copyright 2024 Hugh Field-Richards. All Rights Reserved.