match
A match instruction allows a template that produces
output that is invoked by comparing the input against an XPath expression. It is equivalent to an XSLT match template. Having a distinct
difference between proc and match ensures that there is never confusion. XSLT allows both name and match attributes in <template>, but never with both
missing.
On the occasions where a <template> requires both attributes to be present a simple solution is presented below.
Rexsel insists that the "using" option is always present so that the XSLT conditions are always met.
Syntax
<match> ::= "match" "using" <quote> <xpath expression> <quote>
( "scope" <quote> <qname> <quote> )?
( "priority" <quote> <int> <quote> )?
"{"
<parameter>*
<block templates>+
"}"
Options
using
|
an XPath expression indicating the node and children to match.. |
scope
|
the scope (mode) of this template, matching that defined in an \sqp{apply-remplates} statement (optional). |
priority
|
the numeric priority this template to determine which match is processed when more than one template of the same pattern are
present (optional). |
Elements
Although there are no required elements within the match block, the only time an empty block is used is to absorb matches not done by other
matches defined earlier. For example, if it is required to ensure there is no output when there are elements in the input stream that should
be ignored.
Examples
For example:
stylesheet {
version "1.0"
match using "//concertList" scope "lists" priority "6" {
element "div" {
attribute "id" "concertListAndIndex"
element "div" {
attribute "id" "concertList"
apply-templates scope "lists"
}
}
}
}
Using the command line with errors and symbols selected, this compiles to
<?xml version="1.0" encoding="UTF-8"?>
<!-- Produced using Rexsel compiler 1.0 Build 189 on 20/03/2024 12:29:46 -->
<!-- No Errors -->
<!--
Symbols in context "stylesheet" in line 1, found: 1 symbol
[M] //concertList::lists in line 4
-->
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:template match="//concertList" mode="lists" priority="6">
<xsl:element name="div">
<xsl:attribute name="id">
<xsl:text>concertListAndIndex</xsl:text>
</xsl:attribute>
<xsl:element name="div">
<xsl:attribute name="id">
<xsl:text>concertList</xsl:text>
</xsl:attribute>
<xsl:apply-templates mode="lists"/>
</xsl:element>
</xsl:element>
</xsl:template>
</xsl:stylesheet>
When it is required that an XSLT template combines both a name and match attributes
there is a relatively simple solution. Taking the exmaple above we mnight write
stylesheet {
version "1.0"
match using ”//concertList“ scope "lists" priority "6" {
call processList
}
proc processList scope "lists" priority "6" {
element "div" {
attribute "id" "concertListAndIndex"
element "span" {
attribute "class" "code-dir"
text "<"
apply-templates scope "inline-text"
text ">"
}
}
}
}
which has the same effect as a single template in XSLT
<xsl:template match="//concertList" name="processList" mode="lists" priority="6">
...
</xsl:template>
</xsl:stylesheet>
Errors
Leaving out an expression for scope or other
option.
match using ”//concertList“ scope {
element "div" {
attribute "id" "concertListAndIndex"
element "span" {
attribute "class" "code-dir"
text "<"
apply-templates scope "inline-text"
text ">"
}
}
}
gives
**** (130) Missing using/scope/priority expression in line 4
Insert expression.
Copyright 2024 Hugh Field-Richards. All Rights Reserved.