Reputation: 55
I am new to XQuery and struggling to find anything online that teaches me simple stuff like this. I am trying to just pass in 2 strings, where 1 string is returned as the tag and 1 string is returned as a new value. So far I have this, but am getting build errors.
declare function util:format-promo-tracking-element(
$fieldName as xs:string,
$stringValue as xs:string)
{
let $elementName := $fieldName
if($stringValue = '5.00') then (
let $stringValue := '4.05'
return
element {$elementName}
{
data($stringValue)
}
)
else()
};
I have tried moving the return statement to the end as well.
Upvotes: 0
Views: 193
Reputation: 1993
XQuery is an functional language so trying to assign a new value to an existing variable is not allowed. I think you want something like this.
declare function util:format-promo-tracking-element(
$fieldName as xs:string,
$stringValue as xs:string)
{
let $newValue := if ($stringValue = '5.00') then '4.05' else $stringValue
return
element {$fieldName}
{
$newValue
}
};
There are quite a few basic examples on Wikibooks.
Upvotes: 2