Data Sources

The role of a data source is to provide Stylus Studio with a structure that it can use to compose the XQuery based on how you map individual source objects (XML elements and attributes, or table rows, for example) to nodes in the target structure. Stylus Studio infers the structure from the data source you specify and displays this structure on the Add Source Document pane of the Mapper tab.

In Stylus Studio, a data source can be one or more of the following:

l XML document
l XML Schema (XSD)
l Document type definition (DTD)
l Relational database table
l Microsoft Office Open XML documents
l OpenDocument Format documents
l Zip files

This section covers the following topics:

For information on using a relational database table as a source for XQuery mapper, see Working with Relational Data Sources. For information on using Microsoft Office Open XML, OpenDocument Format, and .zip files as data sources, see Working with Zip Archive Format Files as Data Sources.

Choosing a Data Source

You can use one or more data sources to build an XQuery in Stylus Studio. You might want to select multiple data sources if you need their elements or attributes to fully describe the target structure or the desired XQuery result content, for example.

If you choose an XSD or DTD document, you must also choose an XML instance document to associate with it. Stylus Studio uses the instance document associated with a XSD or DTD source document to generate the XPath doc() function in the finished XQuery code. This document is also used to preview XQuery results.

See Source Documents and XML Instances to learn more about how Stylus Studio treats source documents. See Creating an XQuery Scenario to learn more about XQuery scenarios.

Source Documents and XML Instances

As described previously, Stylus Studio uses the source document you specify to infer a structure you can use to create mappings to the target structure. In addition to the document structure, Stylus Studio needs document content information in order to compose a complete XQuery. You provide this information by associating a XML instance to each source document you specify.

Source documents can have one of three associations, each of which has implications for the XPath expressions written by Stylus Studio when it composes the XQuery code. A source document can be associated with

l Itself. That is, the document represented by structure displayed on the Mapper tab and the XML instance are one in the same. In this situation, Stylus Studio generates the doc() function in the XQuery code. For example:
l The XML document specified in the optional XQuery scenario. Only one source document can be associated with the XQuery scenario. In this situation, Stylus Studio does not generate the doc() function in the XQuery code. For example:
for $book in /books/book
The doc() function is not necessary because Stylus Studio uses the XQuery input document specified in the Scenario Properties dialog box.
By default, Stylus Studio uses the first XML document you add to the XQuery mapper as the source XML for the XQuery scenario, as shown here:
The document specified in the Source XML URL field on the Scenario Properties dialog box is the document used to preview XQuery results. You can select this association for another XML document if you choose, but only one source document may have this association.
l Some other XML instance. A XSD or DTD document used as an XQuery source document must always be associated with an XML instance. In this situation, Stylus Studio generates the doc() function in the XQuery code.

Source icons

Stylus Studio uses different icons to indicate how a source is associated with the other sources used to compose the XQuery.

How to Add a Source Document

This procedure describes how to add an XML document, an XML Schema, or a DTD as a data source. To learn how to add a relational database table as a data source, see Working with Relational Data Sources.

To add an XQuery source document to XQuery mapper:
1. Click the Mapper tab if necessary.
2. Click the Add Source Document button at the top left of the Mapper tab.
The Open dialog box appears.
3. Select the document you want to use as the source document for building the XQuery.
4. Click Open.
If you selected an XML document in Step 3, the document appears in the source document pane of the Mapper tab. Go to Step 5.
If you selected an XSD or DTD document, Stylus Studio displays the Choose Root Element dialog box.
You use this dialog box to associate the XSD or DTD with an XML instance.
b. Use the Browse ( ) button to specify the XML instance to which you want to map the root element you have selected. The root element of the XML document you select must be the same as the element you selected as the root element from the XSD or DTD document.
c. Click OK.

How to Change a Source Document Association

To change a source document association:
1. Right click the source document whose association you want to change.
The source document shortcut menu appears.
2. Click Associate With, and then select the document you want to associate with the source document.

How to Remove a Source Document

To remove a source document from XQuery:
2. Right click on the source document.
The source document shortcut menu appears.
3. Select Remove Schema.

How Source Documents are Displayed

A source document is represented using a page icon, and its name is displayed using a different color to help distinguish it from element and attribute names. The page icon is modified based on the source document's association with other documents. See Source Documents and XML Instances for more information on this topic.

By default, only the file name itself is displayed; if you want, you can display the document's full path by selecting Show Full Path on the document's shortcut menu. (Right-click on the document name to display the shortcut menu.)

Source documents are displayed using the tree view; you can use your keyboard's *, +, and - number pad keys to expand and collapse selected documents.

Document structure symbols

Stylus Studio uses the following symbols to represent nodes in both source and target document structures:

 
Free Stylus Studio XML Training: