Altova FlowForce Server 2025 

Run XSLT with RaptorXML

Home Prev Top Next

This example shows you how to run an XSLT transformation with RaptorXML Server (or RaptorXML+XBRL Server) running under FlowForce Server management. The job will call the xslt function of RaptorXML Server. When you configure the job from the FlowForce Server configuration page, there are two ways to supply the parameters to the xslt function:

 

1.By typing key-value pairs (parameter name and value) in text boxes.

2.By entering a FlowForce Server expression.

 

Both ways are presented in more detail below.

 

Prerequisites

Required licenses: FlowForce Server, RaptorXML (or RaptorXML+XBRL) Server

The FlowForce Web Server and FlowForce Server services must be listening at the configured network address and port

Your FlowForce Server user account has permissions to one of the containers (by default, the /public container used in this example is accessible to any authenticated user).

The job created in this example runs an XSLT stylesheet that processes an input XML file. Both files must exist in some directory on the operation system where FlowForce Server runs, and you must have rights to read and write files in this directory. This example uses the C:\FlowForceExamples\RunXslt directory.

 

Demo files

The job illustrated below will run an XSLT stylesheet called transformation.xslt which takes as input a file called books.xml, and two required parameters, "year" and "genre". The exact content of the files is shown in the code listings below. To use these files in the job, save both code listings with the indicated file names to the C:\FlowForceExamples\RunXslt directory.

 

The XSLT stylesheet looks as follows:

 

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:fn="http://www.w3.org/2005/xpath-functions" exclude-result-prefixes="xs fn">
  <xsl:output method="xml" encoding="UTF-8" byte-order-mark="no" indent="yes"/>
  <xsl:param name="year" as="xs:string" required="yes"/>
  <xsl:param name="genre" as="xs:string" required="yes"/>
  <xsl:template match="/">
    <library>
        <xsl:attribute name="xsi:noNamespaceSchemaLocation" namespace="http://www.w3.org/2001/XMLSchema-instance" select="'library.xsd'"/>
        <last_updated>
          <xsl:sequence select="xs:string(fn:current-dateTime())"/>
        </last_updated>
        <xsl:for-each select="(./books/book)[(fn:string(year) &gt; $year)]">
          <publication>
              <xsl:for-each select="@id">
                <id>
                    <xsl:sequence select="fn:string(.)"/>
                </id>
              </xsl:for-each>
              <author>
                <xsl:sequence select="fn:string(author)"/>
              </author>
              <title>
                <xsl:sequence select="fn:string(title)"/>
              </title>
              <genre>
                <xsl:sequence select="$genre"/>
              </genre>
              <publish_year>
                <xsl:sequence select="xs:string(xs:integer(fn:string(year)))"/>
              </publish_year>
          </publication>
        </xsl:for-each>
    </library>
  </xsl:template>
</xsl:stylesheet>

transformation.xslt

The input XML file looks as follows:

 

<?xml version="1.0" encoding="UTF-8"?>
<books xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="books.xsd">
  <book id="1">
    <author>Mark Twain</author>
    <title>The Adventures of Tom Sawyer</title>
    <category>Fiction</category>
    <year>1876</year>
  </book>
  <book id="2">
    <author>Franz Kafka</author>
    <title>The Metamorphosis</title>
    <category>Fiction</category>
    <year>1912</year>
  </book>
  <book id="3">
    <author>Herman Melville</author>
    <title>Moby Dick</title>
    <category>Fiction</category>
    <year>1851</year>
  </book>
  <book id="4">
    <author>Miguel de Cervantes</author>
    <title>Don Quixote</title>
    <category>Fiction</category>
    <year>1605</year>
  </book>
</books>

books.xml

 

Creating the job

You can create a FlowForce Server jobs to run such an XSLT transformation as follows:

 

1.Log in to the FlowForce Server Web administration interface and open the /public/Examples container. The public/Examples container should already exist if you followed the previous examples; otherwise, create it using the Create | Create Container command.

2.Click Create Job. Next, enter a name and, optionally, a description for the job you are creating. This example uses "RunXslt" as job name.

3.Click new Execution step.

4.Next to "Execute function", browse for the /RaptorXML/xslt function.

fs_xslt_example_02
Note:The xslt function exists directly under the "RaptorXML" container and also in any container that corresponds to a specific RaptorXML release, for example, "2025". For information about differences between the two, see Generic versus release-specific RaptorXML functions.

 

5.Set the Working directory parameter to C:\FlowForceExamples\RunXslt.

6.Set the XSLT File parameter to transformation.xslt. This file must exist in the working directory.

7.Set the XSLT Input parameter to books.xml. This file must also exist in the working directory.

8.Set the Parameters parameter as follows:

 

a. Click the add button next to Parameters. This expands a sub-section within the page, where you can add each parameter name and value individually.

 

fs_xslt_example_03

b. Click the add button for each new parameter that you need to add. To run the XSLT in this example, you will need to enter the parameters as follows:

 

fs_xslt_example_04

 

The XSLT parameters are supplied to the job as key-value pairs. Notice the parameter name and value are entered in separate boxes. Also, the parameter value is enclosed within quotes.

 

9.Under "Service", select the Make this job available via HTTP check box, and enter RunXsltService as name of the service.

10.Under "Credentials", select an existing credential record or specify a local credential. For details, see Credentials.

11.Click Save.

 

This concludes the job configuration part.

 

Supplying XSLT parameters as expression

In the job configuration above, you have supplied the parameter to the xslt function using text boxes. Note that there is a second way to do this, by entering a FlowForce Server expression in the Parameters text box, for example:

fs_xslt_example_05

To use this second approach, click ff-setTo next to Parameters, and then click <Expression>. Make sure that you type the expression very carefully in order to avoid parsing errors. The expression calls the list expression function and builds a list of two key-value pairs. In each key-value pair, the key is the parameter name and the value is the parameter value. Importantly, the parameter values are again enclosed within single quotes.

 

To switch back to the text box layout, click ff-setTo next to Parameters, and then click <Value>.

 

Running the job

To run the job, do one of the following:

 

Go to the Home page and click Show all active triggers and services. Next, click the job's URL displayed in the Info column.

Enter http://127.0.0.1:4646/service/RunXsltService in the browser's address bar. Note that this URL works only if the FlowForce Server service listens at the default host address and port name. If you have defined other host and port settings on the Setup page, change the address accordingly.

If you set the optional Host name field of FlowForce Server on the Setup page, you can execute the web service call directly from the job configuration page, by clicking the fs_ic_call_ws button adjacent to the Make this job available via HTTP check box. The button is not displayed otherwise.

 

If you are asked for credentials when you access the Web service, supply the same credentials you use to log on to FlowForce Server.

 

Important

Supplying your FlowForce Server user credentials for HTTP authentication is only for testing purposes. For production, it is recommended to create a new FlowForce user, grant the Service - Use permission to this user on the container where the job is, and then access the Web service with the corresponding user account. To disable HTTP authentication and make the Web service public, grant the Service - Use permission to the user Anonymous. For details, see How Permissions Work.

 

If the job executes successfully, the browser displays the output of the job, for example:

fs_xslt_example_06

If the job fails, the browser displays a "Service execution failed" message. In this case, check the FlowForce Server job log to identify the error.

© 2018-2024 Altova GmbH