Write a Transform

The transform specifies what to extract from the data.You can use any authoring environment and language appropriate for your project. For XML transformations, choose a technology such as XSLT, Joost (STX), Java, Python, or Perl, based on the goals and scope of the project.

In the price example, the next step is to transform the XML data into a simple two-column delimited format.


The following STX transform, called input_transform.stx, completes the data transformation.

<?xml version="1.0"?>
<stx:transform version="1.0"
  <!-- declare variables -->
  <stx:variable name="itemnumber"/>
  <stx:variable name="price"/>
  <!-- match and output prices as columns delimited by | -->
  <stx:template match="/prices/pricerecord">
    <stx:value-of select="$itemnumber"/>    
    <stx:value-of select="$price"/>      <stx:text>
  <stx:template match="itemnumber">
    <stx:assign name="itemnumber" select="."/>
  <stx:template match="price">
    <stx:assign name="price" select="."/>

This STX transform declares two temporary variables, itemnumber and price, and the following rules.

  1. When an element that satisfies the XPath expression /prices/pricerecord is found, examine the child elements and generate output that contains the value of the itemnumber variable, a | character, the value of the price variable, and a newline.
  2. When an <itemnumber> element is found, store the content of that element in the variable itemnumber.
  3. When a <price> element is found, store the content of that element in the variable price.