Procs and Matches (templates)

Templates in XSLT can be either a named or pattern match template. The former is effectively a function (called a proc in Rexsel) 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>

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.

procs 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 function/proc names that are used by the XSLT processor do not.

Copyright 2024 Hugh Field-Richards. All Rights Reserved.