Re: XProc document templates - a question about undeclared variables

Philip Fennell <Philip.Fennell@marklogic.com> writes:

> Florent,
>
>> If you want the resulting document to contain the 6 chars {, $, f,
>> o, o and }, then you have to escape the curly braces by doubling
>> them: {{$foo}}.
>
> If that were the case then I'd have to un-escape the expression
> before I tried to evaluate the query using p:xquery. I'd be
> exchanging one complication for another.

Not quite. If the input was

  ... element {{$foo}} {$param} ...

The output would be

  ... element {$foo} whatever the param variable was ...

Of course, if you want to interpolate XQuery (or XSLT) with p:document-template,
yes things are going to get a little complicated. For example, unless $param
already contains curly braces, you probably need something like this:

  ... element {{$foo}} {{{$param}}} ...

So that there are curly braces in the resulting XQuery. And, even worse,
if you've got a mixture of markup in there, I'm not sure you'd get the
right escaping of markup characters.

If you're going to send the result through XQuery, it's probably easier to
just declare the variables that you want to come from XProc as external
and do all the interpolation in XQuery:

  declare variable $param external;
  ...
  let $foo as xs:string := 'bar'
  return
    element {$foo} {$param}

                                        Be seeing you,
                                          norm

-- 
Norman Walsh
Lead Engineer
MarkLogic Corporation
www.marklogic.com

Received on Monday, 8 November 2010 14:38:15 UTC