W3C home > Mailing lists > Public > xproc-dev@w3.org > November 2011

RE: Initialize a variable with a parameter port

From: Geert Josten <geert.josten@dayon.nl>
Date: Mon, 21 Nov 2011 21:57:52 +0100
Message-ID: <07e8da20e6243dfa40db466d1468c2ea@mail.gmail.com>
To: Norman Walsh <ndw@nwalsh.com>, XProc Dev <xproc-dev@w3.org>
Hi Florent,

Norm's approach of using a p:parameters step is right.

I have written a small wrapper step around that that makes integrating it
with existing code easier. It is the ut:parameters step you can find in
this file:
https://github.com/grtjn/xproc-ebook-conv/blob/master/src/nl/grtjn/xproc/u
til/utils.xpl. This ut:parameters does two things: identity transform
input to output (or actually short wire input into output in the
declare-step; and apply a p:parameters and pass the results to a secondary
parameters output.

You can put it just below your inputs, outputs and options as a simple
<ut:parameters name="params"/>. After that you have to use a p:group, and
declare p:variables at the top of that with a <p:pipe step="params"
port="parameters"/>.

Kind regards,
Geert

-----Oorspronkelijk bericht-----
Van: Norman Walsh [mailto:ndw@nwalsh.com]
Verzonden: maandag 21 november 2011 20:56
Aan: XProc Dev
Onderwerp: Re: Initialize a variable with a parameter port

Florent Georges <fgeorges@fgeorges.org> writes:
>   I try to get a parameter value in a variable, by connecting the
> variable context to a prameters port and using an expression like
> "/c:param-set/c:param[...]/@value".  But Calabash gives me the
> following error:
>
>     err:XD0008 : More than one document in context for parameter
>     'first' It is a dynamic error if a document sequence appears
>     where a document to be used as the context node is expected.
>
>   I use Calabash 0.9.40.  A complete repro is:

Hmm. Given that there's only one parameter, I'm surprised that doesn't
work. But in the general case, what appears on the parameters input
port is a sequence so that approach isn't going to work reliably
anyway.

The safe way to do this is to wire a p:parameters step into the top of
my:params-try and read from that to initialize the variable. This will,
alas, require another p:group.

Longer term, maybe there should be a p:parameter() *function* that
takes the name of an in-scope parameter and returns its value. Pushing
the parameters into a document in order to read the value back out of
the document does seem like going around the houses.

                                        Be seeing you,
                                          norm

-- 
Norman Walsh
Lead Engineer
MarkLogic Corporation
Phone: +1 413 624 6676
www.marklogic.com
Received on Monday, 21 November 2011 20:58:23 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Monday, 21 November 2011 20:58:23 GMT