Re: Type of documents flowing through ports

Florent,

2012/5/20 Florent Georges <fgeorges@fgeorges.org>

> On 20 May 2012 13:10, mozer wrote:
>
> > Do you want to provide a default content ?
>
>   No.
>

Ok

>
> > What is exactly the use case ?
>
>   There are two different aspects here.  The first one is to be able
> to declare a primary port just for the convenience of connecting it
> implicitly, without imposing the user to write the following when
> he/she doesn't want to pass it (this is really syntactic sugar, but
> XProc syntax is sometimes rather salty, so I think it couldn't hurt):
>
>    <p:input port="source">
>       <p:empty/>
>    </p:input>
>

You might had noticed that you can provide a default value when YOU DECLARE
an input port
[[

An input *declaration* has the following form:

<p:input
  *port* = NCName
  sequence? = boolean
  primary? = boolean
  kind? = "document"
  select? = XPathExpression>
    (p:empty <http://www.w3.org/TR/xproc/#p.empty> |
      (p:document <http://www.w3.org/TR/xproc/#p.document> |
       p:inline <http://www.w3.org/TR/xproc/#p.inline> |
       p:data <http://www.w3.org/TR/xproc/#p.data>)+)?
</p:input>


]]

And can this helps you

[[

If a connection is provided in the declaration, then select may be used to
select a portion of the input identified by the
p:empty<http://www.w3.org/TR/xproc/#p.empty>
, p:document <http://www.w3.org/TR/xproc/#p.document>,
p:data<http://www.w3.org/TR/xproc/#p.data>,
or p:inline <http://www.w3.org/TR/xproc/#p.inline> elements in the
p:input<http://www.w3.org/TR/xproc/#p.input>.
This select expression applies *only* if the default connection is used. If
an explicit connection is provided by the caller, then the default select
expression is ignored.

]]

>
>  The second aspect is to check the documents flowing through a port,
> by checking their root element name:
>
>    <p:declare-step type="my:format-article">
>        <p:input port="source" as="document-node(db:article)"/>
>        ...
>    </p:declare-step>
>
>  Feeding the previous step with something else than a document with a
> root element called "db:article" would then throw a type error, like
> for the "as" attribute in XSLT 2.0.
>

It just a syntactic sugar of something that you can do with
<p:choose>
   <p:when test="/db:article">
   ...
  </p:when>
  <p:otherwise>
    <p:error/>
  </p:otherwise>
</p:choose>

Am I correct ?


Xmlizer

Received on Sunday, 20 May 2012 20:35:26 UTC