Parameters

Apart from options and variables, XProc also offers the possibility to generate parameters. Some steps need/support parameters in order to be able to perform certain tasks.

p:parameters

<p:declare-step type="p:parameters">
   <p:input port="parameters" kind="parameter" primary="false"/>
   <p:output port="result" primary="false"/>
</p:declare-step>

At first, the <p:parameters> step has a <p:input> port of the type “parameter“. This port expects the corresponding parameters. A paramter is identified under XProc as a <c:param> element.

<c:param
  name = QName
  namespace? = anyURI
  value = string/>

<c:param> element requires a QName as identification. As an option a namespace can be assigned. The real content of the parameter is indicated under “value“ as string (character string). These elements are indicated on the input port (“parameter“) and provided in a <c:param-set> element as wrapper (an enclosing element), written on the output port.

<c:param-set>
   c:param*
</c:param-set>

Example

In the following example a series of parameters is generated and also packed and outputted in a <c:param-set> by means of <p:parameters>.

<?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" version="1.0">
  <p:input port="source"/>
  <p:output port="result"/>
  <p:parameters name="params">
    <p:input port="parameters">
      <p:inline>
        <c:param name="parameter1" value="value1"/>
      </p:inline>
      <p:inline>
        <c:param name="parameter2" value="value2"/>
      </p:inline>
    </p:input>
  </p:parameters>
  <p:identity>
    <p:input port="source">
      <p:pipe port="result" step="params"/>
    </p:input>
  </p:identity>
</p:declare-step>

In the example two parameters (<c:param>) are respectively generated in a <p:inline> step. The content of <p:parameters> is read out by <p:identity>. The result is as follows:

<c:param-set>
 <c:param name="parameter2" value="value2"/>
 <c:param name="parameter1" value="value1"/>
</c:param-set>

The two parameters are combined in a <c:param-set>.

p:with-param

<p:with-param
  name = QName
  select = XPathExpression
  port? = NCName>
   ((p:empty |
   p:pipe |
   p:document |
   p:inline |
   p:data)? &
  p:namespaces*)
</p:with-param>

Similar to <p:with-option>, parameters can be assigned to steps supporting parameters by indicating the appropriate XPath expression with the help of <p:with-param>.

A QName which corresponds to the desired parameter has to be assigned to the “name“ attribute. “select“ expects an XPath expression representing the value of the parameter. A further port can be optionally indicated under “port“. This port shall receive the generated parameter. However, the primary parameter input port is adopted as standard. If a port is indicated, it must accept parameters (which means it has to be a parameter input port), otherwise a static error wolud occur.

Example

In the following example a step is operated by <p:with-param> in order to create a parameter.

<?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" version="1.0">
  <p:input port="source">
    <p:inline>
      <demo/>
    </p:inline>
  </p:input>
  <p:output port="result"/>
  <p:xslt name="xslt">
    <p:with-param name="ExampleParameter" select="'Trivial Example'">
      <p:empty/>
    </p:with-param>
    <p:input port="stylesheet">
      <p:inline>
        <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
         xmlns:xd="http://www.oxygenxml.com/ns/doc/xsl" version="2.0">
          <xsl:param name="ExampleParameter"/>
          <xsl:template match="/">
            <example>
              <xsl:value-of select="$ExampleParameter"/>
            </example>
          </xsl:template>
        </xsl:stylesheet>
      </p:inline>
    </p:input>
</p:xslt>
</p:declare-step>

In the example a “ExampleParameter“ parameter with the content “Trivial Example“ is generated. This parameter is read out by “xsl-value-of select=“$ExampleParameter“ in the <p:xslt> step in the inline generated XSLT stylesheet. So, the result of this pipeline outputs the value of the parameter.

<< back next >>