call/with

To invoke a named proc the call is used. A name must be given together with a set of optional parameters (with) passed through to the proc.

Syntax
<call> ::= "call" <proc name> ( "{" <with>* "}" )? <with> ::= "with" <qname> ( <xpath expression> | ( "{" <block templates>+ "}" ) )
Options
name a name defining the name of the proc to call.
Elements

Zero or more with parameter definitions within a block.

Examples

For example the following is a recursive routine common.substring-after-last that includes a call to itself.

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

which translates to

<template name="common.substring-after-last"> <param name="string"/> <param name="delimiter"/> <choose> <when test="contains($string, $delimiter)"> <call-template name="common.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>
Errors

Taking the above example, spelling the name incorrectly.

call common.substring-after-las { with string "substring-after($string, $delimiter)" with delimiter "$delimiter" }

will give the error

**** (116) Could not find "common.substring-after-las" in line 9 Check "common.substring-after-las" is defined in current block.

A simple misspelling with a call statement

call common.substring-after-last { wit string "substring-after($string, $delimiter)" with delimiter { constant str "A constant string" value "$delimiter" } }

will give

**** (106) Unexpected symbol "wit" in line 10 Check spelling, did you mean "with" ? **** (136) Unmatched brackets in 1 Too many open brackets?
Copyright 2024 Hugh Field-Richards. All Rights Reserved.