W3C home > Mailing lists > Public > xproc-dev@w3.org > October 2010

RE: Simplifying a series of simple p:xslt steps

From: <vojtech.toman@emc.com>
Date: Tue, 12 Oct 2010 03:44:54 -0400
Message-ID: <997C307BEB90984EBE935699389EC41C026A5A14@CORPUSMX70C.corp.emc.com>
To: <xproc-dev@w3.org>
Just for completeness, the recursive pipeline below can be used for applying a sequence of XSL transformations to the source document. The pipeline takes an XML document, a sequence of XSLT stylesheets, and zero or more parameters for the transformations. It's not really less verbose and is probably also harder to read than the original pipeline, but it shows how you can use XProc to deal with sequences of operations whose number is not fixed or known in advance.

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

  <p:input port="source" primary="true"/>
  <p:input port="stylesheets" sequence="true"/>
  <p:input port="parameters" kind="parameter"/>
  <p:output port="result"/>

  <p:count>
    <p:pipe step="main" port="stylesheets"/>
  </p:count>
    
  <p:choose>
    <p:when test="/c:result = 0">
      <!-- no more stylesheets: return the source document unchanged -->
      <p:identity>
        <p:input port="source">
          <p:pipe step="main" port="source"/>
        </p:input>
      </p:identity>
    </p:when>
    <p:otherwise>
      <p:split-sequence test="position() = 1" initial-only="true" name="split">
        <p:input port="source">
          <p:pipe step="main" port="stylesheets"/>
        </p:input>
      </p:split-sequence>

      <!-- apply the first stylesheet -->
      <p:xslt name="xslt">
        <p:input port="source">
          <p:pipe step="main" port="source"/>
        </p:input>
        <p:input port="stylesheet">
          <p:pipe step="split" port="matched"/>
        </p:input>
      </p:xslt>

      <!-- apply the remaining stylesheets recursively -->
      <ex:transform>
        <p:input port="source">
          <p:pipe step="xslt" port="result"/>
        </p:input>
        <p:input port="stylesheets">
          <p:pipe step="split" port="not-matched"/>
        </p:input>
      </ex:transform>
    </p:otherwise>
  </p:choose>
</p:declare-step>

Regards,
Vojtech

--
Vojtech Toman
Consultant Software Engineer
EMC | Information Intelligence Group
vojtech.toman@emc.com
http://developer.emc.com/xmltech

Received on Tuesday, 12 October 2010 07:47:56 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Tuesday, 12 October 2010 07:47:56 GMT