XProc steps

A | B | C | D | E | F | G | H | I | J | K | L | M | N | O | P | Q | R | S | T | U | V | W | X | Y | Z

p:xslt

<p:declare-step type="p:xslt">
   <p:input port="source" sequence="true" primary="true"/>
   <p:input port="stylesheet"/>
   <p:input port="parameters" kind="parameter"/>
   <p:output port="result" primary="true"/>
   <p:output port="secondary" sequence="true"/>
   <p:option name="initial-mode"/> <!-- QName -->
   <p:option name="template-name"/> <!-- QName -->
   <p:option name="output-base-uri"/> <!-- anyURI -->
   <p:option name="version"/> <!-- string -->
</p:declare-step>

With the help of the <p:xslt> step, XSLT transformations can be performed. The step has three input ports which indicate the document to be read in, the XSLT stylesheet to be transformed and optional parameters. The step also has two output ports. The primary output port (“result“) delivers the primary result of the respective transformation, the second output port “secondary“ outputs all other output documents (if any have been generated). Furthermore, options are available. In this way, the user can make an indication under “inital-mode“ which may influence the behaviour of the transformation. However, this mode must have been defined in the underlying XSLT stylesheet. Under “template-name“, the name of a “Named Template“ can be indicated in the XSLT stylesheet. This means that the transformation begins with this template. With the help of “output-base-uri“, an indication regarding the output of the XSLT transformation in the file system can be given. “Version“ indicates the XSLT version to be used (1.0 or 2.0). All options are optional.

Example

In this example a XSLT stylesheet shall be executed which transforms the file to be read in into a XHTML page, indicating the film titles in a list.

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" exclude-result-prefixes="xs" xmlns:xd="http://www.oxygenxml.com/ns/doc/xsl" version="2.0">
   <xsl:output method="xhtml"/>
   <xsl:template match="/">
      <html>
         <body>
            <h1>Film list</h1>
            <ul>
               <xsl:apply-templates select="//Title"/>
            </ul>
         </body>
      </html>
   </xsl:template>
   <xsl:template match="Title">
      <li>
         <xsl:value-of select="."/>
      </li>
   </xsl:template>
</xsl:stylesheet>

The shown XSLT stylesheet generates a XHTML page on the basis of the nature of the read in XML file. This page generates an unsorted list with the respective film titles. This stylesheet shall now become part of the XProc document.

<?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:document href="FilmCollection.xml"></p:document>
   </p:input>
   <p:output port="result"/>
   <p:xslt>
      <p:input port="stylesheet">
         <p:document href="xslt_stylesheet.xsl"></p:document>
      </p:input>
      <p:input port="parameters">
         <p:empty/>
      </p:input>
   </p:xslt>
</p:declare-step>

The required input ports are defined in the <p:xslt> step. So, the XSLT stylesheet to be read in is indicated in the “stylesheet“ port via <p:document>. The example assumes that all files are located in the same directory. Since the stylesheet is provided with no parameters, this has to be clearly indicated by <p:empty> (otherwise this would lead to a “dynamic error“).

The result of the transformation is as follows:

<html xmlns:xd="http://www.oxygenxml.com/ns/doc/xsl">
   <body>
      <h1>Film list</h1>
      <ul>
         <li>Star Wars: Episode IV - A New Hope</li>
         <li>Eraserhead</li>
         <li>Unforgiven</li>
      </ul>
   </body>
</html>