declare function r:constrainTarget($element-name as xs:string, $element-value as xs:string?) as xs:string?
{
if(fn:starts-with($element-name, "target:"))
then
let $constraint := r:getTargetConstraint($element-name)
return
if($constraint and $element-value)
then
let $element-value :=
for $apply in $constraint/apply
return
let $apply-type := element {data($apply/@type)} {}
return typeswitch($apply-type)
case element(length)
return substring($element-value, 1, number(data($apply/@value)))
case element(lower-case)
return lower-case($element-value)
default
return $element-value
return $element-value
else $element-value
else
$element-value
};