Example of Transforming XML

The following is an example of using the Transform XML activity to change an input XML document into the desired output schema. In this example, books are cataloged and processed. The user enters a book’s information into a web interface, and the web input form supplies a new catalog number and the date it was entered into the catalog. The process definition accepts the incoming web request, transforms the XML and adds the catalog number and date, enters the data into a database, then returns the results to the user. A process definition using the Transform XML activity illustrates the process definition for this example.

Figure 117: A process definition using the Transform XML activity

The Transform XML activity uses an XSLT file that accepts two input parameters, catalogNumber and catalogDate. These input parameters are added as elements to the Book schema. The following is the source of the XSLT File shared configuration resource for the example Transform XML activity:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"
   xmlns:pfx="http://www.books.org">
<xsl:param name="catalogNumber"> <!--type="string"--></xsl:param>
<xsl:param name="catalogDate"> <!--type="string"--></xsl:param>
<xsl:template match="/*">
   <pfx:BookStore>
      <xsl:for-each select="Book">
         <xsl:call-template name="handle-book">
            <xsl:with-param name="inDate" select="$catalogDate"/>
         </xsl:call-template>
      </xsl:for-each>
   </pfx:BookStore>
</xsl:template>
<xsl:template name ="handle-book">
   <xsl:param name="inDate"> <!--type="string"--></xsl:param>
      <pfx:Book>
         <pfx:Title><xsl:value-of select="Title"/></pfx:Title>
         <pfx:Author><xsl:value-of select="Author"/></pfx:Author>
         <pfx:Date><xsl:value-of select="$inDate"/></pfx:Date>
         <pfx:ISBN><xsl:value-of
            select="$catalogNumber"/></pfx:ISBN>
         <pfx:Publisher><xsl:value-of
            select=""TIBCO Software Inc./></pfx:Publisher>
      </pfx:Book>
</xsl:template>
</xsl:stylesheet>

When you configure the Transform XML activity, you specify the incoming XML to transform any input parameters to the schema. Input for the example Transform XML activity illustrates the input for the example Transform XML activity.

Figure 118: Input for the example Transform XML activity

The stylesheet has two input parameters. The XPath if statement is used to place the correct names and values into the correct parameters. Each parameter is specified as a name/value pair. Notice that the name of each parameter corresponds to the name specified for that parameter in the XSLT file.

The output of the Transform XML activity is a text string containing the XML. In our example process definition, we must insert the transformed data into a database table. To map the transformed data into the database UPDATE statement, the data must first be represented as a schema. To do this, we use the Parse XML activity to parse the output of Transform XML into an XML schema.