parameter
A parameter statement can occur either at the
root level with the stylesheet or as a definition of what parameters are used by a proc. Parameters can be declared with a default value either as a simple
string or a block.
Syntax
<parameter> ::= “parameter” <name> (
( <quote> <xpath expression> <quote> ) | ( “{” ( <block template> )+ “}” )
)?
Options
name
|
The name of this parameter. |
xpath expression
|
An XPath expression returning a value (required if block not present). |
Elements
If there is an element block then there should not be an XPath expression. Note that as both block and expressions are used for a default
value for the parameter so it is valid for neither to be present.
Examples
A set of simple parameters, noting that param-2 and param-3 are notionally the
same.
stylesheet {
version "1.0"
parameter param-1
parameter param-2 "'default-value'"
parameter param-3 {
text "default-value"
}
}
compiles to
<?xml version="1.0" encoding="UTF-8"?>
<stylesheet
xmlns="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<param name="param-1"/>
<param name="param-2" select="'default-value'"/>
<param name="param-3">
<text>default-value</text>
</param>
</stylesheet>
Errors
Consider this list of multiple errors.
stylesheet {
version "1.0"
// Missing name
parameter
// Misssing name
parameter "'Some text'"
// Blank block which is quasi valid (translates to valid XSLT)
parameter valid-param-1 { }
// Cannnot have value and block
parameter invalid-param-2 "'Some text'" { }
// Duplicate name
parameter valid-param-1
// Duplicate name + undefined symbol
parameter valid-param-2 {
value "$valid-param-4"
}
}
will produce a miscellany of errors
**** (115) Expected name after "parameter" in line 8
Insert name.
**** (115) Expected name after "parameter" in line 11
Insert name.
**** (129) There must be either a simple/default value or enclosed templates in line 14
Supply either expression/text or enclosed templates.
**** (151) "parameter" requires one or more "choose, apply-templates, attribute-set, number, foreach, attribute, copy, apply-imports, element, message, text, comment, fallback, variable, if, copy-of, processing-instruction, value, call" in line 14
Check syntax requirements for "parameter" or insert in block
**** (105) Unexpected symbol "{" found in "parameter" in line 17
Check spelling, missing expression, bracket or quote?
**** (138) Missing or empty block in 17
Supply block
**** (136) Unmatched brackets in 1
Too many open brackets?
The statement
parameter valid-param-1 { }
is valid but spurious as the block is empty. It will compile correctly and equivalent to
Another important error is when parameters are declared in procs etc. Parameters must be declared at the start of a proc. So for example
proc substring-after-last {
parameter string
choose {
when "contains($string, $delimiter)" {
call substring-after-last {
with string "substring-after($string, $delimiter)"
with delimiter "$delimiter"
}
}
otherwise {
value "$string"
}
}
parameter delimiter
}
will give the error report
**** (131) Parameter "delimiter" in "proc:substring-after-last" in line 19 must follow declaration.
Check order.
Copyright 2024 Hugh Field-Richards. All Rights Reserved.