Source Documents

In Stylus Studio, a source document in the XSLT mapper can be an XML document, an XML Schema (XSD), or a document type definition (DTD). The role of a source document is to provide Stylus Studio with a structure that it can use to compose the XSLT stylesheet, based on how you map individual source document elements and attributes to nodes in the target structure. Stylus Studio infers the target structure from the document (XML, XSD, or DTD) you specify and displays this structure on the Mapper tab.

In this section

This section covers the following topics:

Choosing Source Documents

You can use one or more source documents to build a stylesheet in the Stylus Studio XSLT mapper. You might want to select more than one document if you need their elements or attributes to fully describe the target structure or the desired XSLT result content, or if you want to aggregate multiple sources in a single document, 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 an XSD or DTD source document to generate the XPath document() function in the finished XSLT. As a result, it is this document that is used to preview XSLT results.

Tip

 

If you want to examine the contents of the XML document specified as the source file in the scenario, click Open XML From Scenario , which is at the top of the XML mapper window. Stylus Studio displays the source document in the XML editor.

For more information

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

Source Documents and XML Instances

As described previously, Stylus Studio uses the source documents you specify to display 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 correct XSLT stylesheet. You provide this information by associating a XML instance to each source document you specify.

Types of associations

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

  • 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 document() function in the XSLT stylesheet. For example:
    document("file://c:\Program Files\Stylus 
    Studio\examples\simpleMappings\catalog.xml")/books/book
                           
    
                        

Note

 

The previous example shows the XSLT that results when an XML document is used to specify the source structure. This is not possible with XSD or DTD source documents.

  • The XML document specified in the XSLT scenario. Only one source document can be associated with the XSLT scenario. In this situation, Stylus Studio does not generate the document() function in the XSLT stylesheet. In this situation, the document() function is not necessary because Stylus Studio uses the XSLT input document specified in the Scenario Properties dialog box.
  • By default, Stylus Studio uses the first XML document you add to the XSLT mapper as the source XML for the XSLT scenario, as shown here:

    Figure 216. XSLT Scenario

    The document specified in the Source XML URL field on the Scenario Properties dialog box is the document to which the XSLT is applied when you preview the XSLT. You can select this association for another XML document if you choose, but only one source document may have this association.

Note

 

If you specify an XML document as the first source document, Stylus Studio creates a scenario for you automatically, using that document as the scenario's source XML. If you specify some other type of document (XSD or DTD), Stylus Studio prompts you to create a scenario - and to specify an XML document as the source - when you preview the XSLT. See Creating an XSLT Scenario.

  • Some other XML instance. A XSD or DTD document used as a mapper source document must always be associated with an XML instance. In this situation, Stylus Studio generates the document() function in the XSLT stylesheet when accessing nodes of the document structure.

Source document icons

Stylus Studio uses different document icons to indicate how a source document structure is related to corresponding XML document content.

Icon
Meaning
The source document is associated with itself. This is the default for most XML documents (and XML documents only).
The source document is associated with default XML document specified in the Source XML URL field in the XSLT scenario. This is the case with the first XML document you add to XSLT mapper, but you can change this association manually if you choose. See How to change a source document association.
The source document is associated with a separate XML document instance. XSD and DTD source documents are always associated with an XML instance.
Table 32. Source Document Icons

How to change a source document association

To change a source document association:
1. Click the Mapper tab if necessary.
2. Right click the source document whose association you want to change.

The source document shortcut menu appears.

3. Click Associate With, and then select the document you want to associate with the source document.

How to Add a Source Document

To add a source document to XSLT 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 to map to the target document.
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.

Figure 217. Choose Root Element Dialog Box

You use the Associate With field to associate the XSD or DTD with an XML instance.

Note

 

The Associate With field appears only when you add a second document to the XSLT mapper source and that document is an XSD or DTD. You use it to specify the XML instance that you want to associate with the XSD or DTD. This field does not appear if the XSD or DTD is the first source document you add to the XSLT mapper - Stylus Studio uses the XML Source document specified in the Scenario Properties dialog box as the XML instance in this case.

a. Select the element from the XSD or DTD document that you want to use as the root element. The Choose root element drop-down list displays elements defined in the document you selected in step 3.
b. Use the Browse ( ) button to specify the XML instance to which you want to associate the document you have chosen as your structure. The root element of the XML document you select should be the same as the element you selected as the root element from the XSD or DTD document.
c. Click OK.

The document appears in the source document pane of the Mapper tab. Go to step 5.

5. To add another source document, return to step 2.

How to Remove a Source Document

Note

 

A source document cannot be removed from XSLT mapper if it is mapped to the target structure. See Removing Source-Target Maps.

To remove a source document from the XSLT mapper:
1. Click the Mapper tab if necessary.
2. Remove any maps from the source document to the target schema. (See Removing Source-Target Maps if you need help with this step.)
3. Right click on the source document.

The source document shortcut menu appears.

4. Select Remove Schema.

How Source Documents are Displayed

A source document is represented in the mapper using a document icon; its name is displayed using a different color to help distinguish the document from elements and attributes. The document 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.)

Figure 218. Source Document Display

Source documents are displayed using the tree view; you can use your standard 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

Symbol
Meaning
Repeating element
Element
Attribute
Table 33. Document Structure Symbols

See Source document icons to learn about the different ways source document icons are depicted.

Getting source document details

If you want details about the source document that are not available in tree view, you can open the document by selecting Open from the document's shortcut menu. When you open a document this way, Stylus Studio displays it in the XML editor. XSD and DTD documents are displayed on the XML editor's Schema tab.

 
Free Stylus Studio XML Training: