Configuring Data Sources

The source for the information required for the desired report comes from two files:

  • A flat file, booksXML.txt, that contains ISBN, title, manufacturer, and release date information for every book in inventory.
  • An EDI file, order.edi, that contains title, ISBN, and quantity information for every book currently on order.

Neither of these files provides data in XML format, so they will have to be converted to XML. We will use Stylus Studio's built-in converters for this task.

Ways to Configure Non-XML Data Sources

You use ConvertToXML nodes to specify a non-XML data source in an XML pipeline. There are two ways to do this:

  • Convert the source file using a built-in Stylus Studio adapter or user-defined converter, and then drag the resulting document and drop it on the XML pipeline canvas.
  • Create the ConvertToXML node in the XML pipeline using the Toolbox, and then specify the source file and the Stylus Studio adapter or user-defined converter you want to use to convert it to XML.

While both require a similar number of steps, converting a source file can be more economical as it creates a resource that you can reuse in the XML pipeline, and elswhere in Stylus Studio. Both procedures are described in the following sections.

Convert booksXML.txt Using an Adapter

To convert booksXML.txt using an adapter:
1. Select File > Open from the menu.

The Open dialog box appears.

2. Navigate to the examples\pipeline\order folder where you installed Stylus Studio.
3. Change the Files of type field to All Files.
4. Select booksXML.txt.
5. Select the Convert to XML using adapter check box at the bottom of the Open dialog box.
6. Click Open.

Stylus Studio displays the Select XML Converter dialog box.

7. Select the Comma-Separated Values converter.

The booksXML.txt source file happens to use a vertical bar (|) as its separator character.

Tip

 

To view the source .txt and .edi files, double-click them in the Project window to display them in a Stylus Studio editor.

Figure 397. Select XML Converter Dialog Box

8. Change the value in the Separator property to a vertical bar (|).
9. Change the value in the First row contains field names to Yes.
10. Click OK.

The booksXML.txt file appears in the Other Documents folder in the Project window. If you hover the mouse pointer over the file name, you will see the full specification of the adapter URL used to convert it.

11. Drag booksXML.txt and drop it on the XML pipeline canvas.

Stylus Studio creates a ConvertToXML node with its input port already specified.

Create a ConvertToXML Node for booksXML.txt

To create XML data from a non-XML source in the XML Pipeline Editor:
1. Drag the ConvertToXML icon from the Toolbox pane and drop it on the XML pipeline canvas.

Stylus Studio creates a ConvertToXML node and displays it in the XML pipeline diagram.

2. Display the Properties window ( View > Properties) if it is not already open.
3. Display the Project window ( View > Project) if it is not already open.
4. Click the input port on the ConvertToXML node.

The properties for the input port are displayed in the Properties window.

5. Click the Default Value field; click the more button ( ) when it appears.

Stylus Studio displays the Default Value dialog box.

Figure 398. Default Value Dialog Box

6. Click the Read default value from this URL radio button, and then navigate to examples\pipelines\order\ folder where you installed Stylus Studio and select booksXML.txt.
7. Click OK.

The input port on the ConvertToXML Node turns green, indicating that a source document has been specified as the input.

Next, we need to specify which built-in converter to use to convert booksXML.txt to XML.

8. Click the ConvertToXML node in the XML pipeline diagram.
9. Click the Adapter URL field in the Properties window; click the more button ( ) when it appears.

Stylus Studio displays the Select XML Converter dialog box.

10. Select the Comma-Separated Values converter.

The booksXML.txt source file happens to use a vertical bar (|) as its separator character.

Tip

 

To view the source .txt and .edi files, double-click them in the Project window to display them in a Stylus Studio editor.

Figure 399. Select XML Converter Dialog Box

11. Change the value in the Separator property to a vertical bar (|).
12. Change the value in the First row contains field names to Yes.
13. Click OK.

The ConvertToXML node representing the conversion of the booksXML.txt file to XML is now completely specified, except for the output. We will address that in the section Setting the XQuery Node Data Sources.

Create a ConvertToXML Node for order.edi

Next, using the procedure described in either Convert booksXML.txt Using an Adapter or Create a ConvertToXML Node for booksXML.txt, create a ConvertToXML node for the order.edi file. Note the following changes:

  • Use select order.edi as the source document.
  • Select Electronic Data Interchange (EDI) from the Select XML Converter dialog box. Accept all default values.

Renaming Nodes

When you add a second node of the same type using the Toolbox, Stylus Studio gives the second node the same name as the first, with a number to make it unique. If you create a node by dragging a document and dropping it on the canvas, Stylus Studio gives the node the same name as the file.

Depending on how you created the ConvertToXML nodes in the XML pipeline, they are named either:

  • Convert to XML, and Convert to XML #2, or
  • booksXML.txt and order.edi

You can reame nodes using the following procedure:

To rename a node:
1. Select the node you want to rename in the XML pipeline diagram.
2. Click the value in the Name field in the Properties window.
3. Type the new name and press Enter.

Tip

 

Node names are displayed as tooltips in the XML pipeline diagram when you hover the pointer over the node. You can also create labels for the diagram and for nodes within the diagram. See <xHyperlink>Labeling for more information.

The XML Pipeline So Far

At this point, we have defined the converters to be used to convert our non-XML data sources to XML. The resulting XML pipeline, myOrders.pipeline, looks something like this:

Figure 400. myOrders.pipeline After Defining Non-XML Data Sources

In the next stage of the process, we will specify the XQuery file that we will use to join the data from these two files.

 
Free Stylus Studio XML Training:
W3C Member