RE: Parameter serialization

I am sure I mentioned the very same issue at least once on this list, might
already by somewhere on the vNext list. To me there is no functional logic
in having a sequence of parameter sets. You yourself just recently
mentioned that it can be awkward to not be able to use a sequence as input
for variables. So, that also applies to when you try to access parameters
when you are declaring a variable. I had this helper step that I added to
my own steps, just to facilitate this, and wrap param-sets to flatten the
sequence.



So, +1



*Van:* Jostein Austvik Jacobsen [mailto:josteinaj@gmail.com]
*Verzonden:* dinsdag 2 juli 2013 17:41
*Aan:* XProc Dev
*Onderwerp:* Parameter serialization



When you write an XProc step that has a parameter input port, the XProc
spec does not strictly say how the parameters are serialized on the input
port.



For instance, calabash outputs a sequence of c:param and c:param-set
elements, (basically just giving you whatever you put in, and appends a
c:param-set at the end containing all your p:with-param parameters).
calumet on the other hand gives you a sequence of c:param elements (no
c:param-set wrapping).



I don't know why the spec explicitly states that you can't have a
non-sequence parameter input port, but if it had been possible to declare a
non-sequence parameter input port, then all the parameters would have to be
combined into a c:param-set. I see no reason to have a sequence of
parameters really, since the serialization of the parameters are undefined
and you can't have multiple parameters with the same name (for some reason
- I'm guessing the XSLT use-case).



I would find it easier to work with parameters if they were all wrapped
into a single c:param-set. Alternatively I could live with a sequence of
c:params (like calumet does it); the important thing is that the format is
predictable so that I don't have to preprocess the parameters before
applying any of my own transformations to the set of parameters.



The following XProc script provides some parameters to a step and outputs
how they are serialized. Note also that this script fails if you remove the
sequence attribute from the p:output in the ex:identity step. If you
haven't specified sequence="true" on the parameter input port, then there
are no apparent reason for getting the
XD0006<http://www.w3.org/TR/xproc/#err.D0006>error unless you have
read the part of the spec that states that parameter
ports defaults to sequence="true".

<?xml version="1.0" encoding="UTF-8"?>

<p:declare-step xmlns:p="http://www.w3.org/ns/xproc" xmlns:c="
http://www.w3.org/ns/xproc-step" xmlns:ex="http://example.net/ns"
version="1.0">



    <p:output port="result" sequence="true"/>



    <p:declare-step name="main" xmlns:p="http://www.w3.org/ns/xproc"
xmlns:c="http://www.w3.org/ns/xproc-step" xmlns:ex="http://example.net/ns"
type="ex:identity" version="1.0">



        <p:input port="source" primary="true" kind="parameter"
sequence="true"/>



        <p:output port="result" sequence="true">

            <p:pipe port="source" step="main"/>

        </p:output>



        <p:sink>

            <p:input port="source">

                <p:empty/>

            </p:input>

        </p:sink>



    </p:declare-step>



    <ex:identity>

        <p:with-param name="with-param-before"
select="'with-param-before'"/>

        <p:with-param name="param5" select="'value5-1'"/>

        <p:input port="source">

            <p:inline>

                <c:param-set xmlns:c="http://www.w3.org/ns/xproc-step">

                    <c:param name="param1" value="value1"/>

                    <c:param name="param3" value="value3-1"/>

                </c:param-set>

            </p:inline>

            <p:inline>

                <c:param-set xmlns:c="http://www.w3.org/ns/xproc-step">

                    <c:param name="param2" value="value2"/>

                    <c:param name="param3" value="value3-2"/>

                    <c:param name="param4" value="value4-1"/>

                    <c:param name="param5" value="value5-2"/>

                </c:param-set>

            </p:inline>

            <p:inline>

                <c:param name="unwrapped-param"
value="unwrapped-param-value"/>

            </p:inline>

        </p:input>

        <p:with-param name="with-param-after" select="'with-param-after'"/>

        <p:with-param name="param4" select="'value4-2'"/>

    </ex:identity>



</p:declare-step>





This is the result for calabash:

<c:param-set xmlns:c="http://www.w3.org/ns/xproc-step">

    <c:param name="param1" value="value1"/>

    <c:param name="param3" value="value3-1"/>

</c:param-set>

<c:param-set xmlns:c="http://www.w3.org/ns/xproc-step">

    <c:param name="param2" value="value2"/>

    <c:param name="param3" value="value3-2"/>

    <c:param name="param4" value="value4-1"/>

    <c:param name="param5" value="value5-2"/>

</c:param-set>

<c:param xmlns:c="http://www.w3.org/ns/xproc-step" name="unwrapped-param"
value="unwrapped-param-value"/>

<c:param-set xmlns:c="http://www.w3.org/ns/xproc-step">

    <c:param name="param5" namespace="" value="value5-1"/>

    <c:param name="param4" namespace="" value="value4-2"/>

    <c:param name="with-param-after" namespace="" value="with-param-after"/>

    <c:param name="with-param-before" namespace=""
value="with-param-before"/>

</c:param-set>





This is the result for calumet:

<c:param name="with-param-before" namespace="" value="with-param-before"
xmlns:c="http://www.w3.org/ns/xproc-step"/>

<c:param name="param5" namespace="" value="value5-2" xmlns:c="
http://www.w3.org/ns/xproc-step"/>

<c:param name="param1" namespace="" value="value1" xmlns:c="
http://www.w3.org/ns/xproc-step"/>

<c:param name="param3" namespace="" value="value3-2" xmlns:c="
http://www.w3.org/ns/xproc-step"/>

<c:param name="param2" namespace="" value="value2" xmlns:c="
http://www.w3.org/ns/xproc-step"/>

<c:param name="param4" namespace="" value="value4-2" xmlns:c="
http://www.w3.org/ns/xproc-step"/>

<c:param name="unwrapped-param" namespace="" value="unwrapped-param-value"
xmlns:c="http://www.w3.org/ns/xproc-step"/>

<c:param name="with-param-after" namespace="" value="with-param-after"
xmlns:c="http://www.w3.org/ns/xproc-step"/>





I would've liked:

<c:param-set xmlns:c="http://www.w3.org/ns/xproc-step">

    <c:param name="with-param-before" value="with-param-before"/>

    <c:param name="param5" value="value5-2"/>

    <c:param name="param1" value="value1"/>

    <c:param name="param3" value="value3-2"/>

    <c:param name="param2" value="value2"/>

    <c:param name="param4" value="value4-2"/>

    <c:param name="unwrapped-param" value="unwrapped-param-value"/>

    <c:param name="with-param-after" value="with-param-after"/>

</c:param-set>





What do you think?



Jostein

Received on Wednesday, 10 July 2013 13:37:59 UTC