W3C home > Mailing lists > Public > public-xml-processing-model-wg@w3.org > November 2010

Simplified template element notes

From: Norman Walsh <ndw@nwalsh.com>
Date: Thu, 04 Nov 2010 14:18:16 +0100
To: public-xml-processing-model-wg@w3.org
Message-ID: <m2bp65dy7b.fsf@nwalsh.com>
Notes from our simplified element discussion. These will be incorporated
into the minutes, but in the meantime...

The WG discussed the problem of a "simplified template" step,
something that would make it easier to construct documents with
dynamically generated content.

There seem to be two paths: a clean-slate design targetted at XProc
V.next where we can change the semantics of pipelines in any way we
want, or a design that would be valid in XProc 1.0. Although the
former might produce the best results, for the short and medium term,
it seemed wise to consider what we could accomplish within the
constraints of XProc 1.0.

After much discussion, the WG concluded that we could achieve
significant simplification with two new XProc atomic steps:
p:in-scope-names and p:document-template.

  <p:output port="result" primary="false"/>

The p:in-scope-names step is roughly analagous to the p:parameters
step. It creates a c:param-set document containing one c:param element
for each in-scope variable and option. The order of the c:param
elements is implementation-dependent.

  <p:input port="source"/>
  <p:input port="context" sequence="true"/>
  <p:input port="parameters" kind="parameters"/>

The p:document-template step makes a verbatim copy of its source input
with one exception: within attribute values and element content, every
expression delimited by curly braces is treated as an XPath expression
and replaced by the result of evaluating that expression.

* The context item used during evaluation of the expression is the
  document that appears on the context port. It is a dynamic error
  err:XDxxxx if more than one document appears on the context port.

  In an XPath 1.0 implementation, if p:empty is given or implied as
  the context, an empty document node is used as the context node. In
  an XPath 2.0 implementation, the context item is undefined. It is a
  dynamic error (err:XD0026) if the select expression makes reference
  to the context node, size, or position when the context item is

* The names of all the parameters passed to the step are available as
  variable names during expression evaluation.

* If an expression selects one or more nodes from the context, a copy
  of those nodes is inserted in the result document, unless the
  expression occurs in an attribute value in which case their string
  value is used.

* The sequence "{{" is replaced by a single, literal "{".

* The sequence "}}" is replaced by a single, literal "}".

* The version of XPath supported by the step is

Suppose you wish to construct the following document:

  <c:request method="POST" href="http://example.com/post"
             username="user" password="password">

Where the method, href, username, and password are computed by the
pipeline as either options or variables and the body of the post is
selected from one of the pipeline's input documents (say

Using only XProc 1.0 standard steps, this can be accomplished with
several successive p:add-attribute steps and a p:insert step. (There
may be other ways as well, though they are all a bit tedious.)

Using these new steps, it's much simpler:

  <p:in-scope-names name="vars"/>

    <p:input port="source">
        <c:request method="{$method}" href="{$uri}"
                   username="{$user}" password="{$password}">
            { /h:html/h:body/h:div[3] }
    <p:input port="context" sequence="true">
      <p:pipe step="main" port="result"/>
    <p:input port="parameters">
      <p:pipe step="vars" port="result"/>

This is in many ways like a simplified stylesheet in XSLT. In fact,
aside from the new semantics associated with curly-braces in element
content, it could be implemented in XSLT. Conversely, it could be
implemented in XQuery, if you were willing or able to escape all of
the markup and pass it to the p:xquery step in a c:query element.

                                        Be seeing you,

Norman Walsh
Lead Engineer
MarkLogic Corporation

Received on Thursday, 4 November 2010 13:18:56 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Thursday, 4 November 2010 13:18:56 GMT