Home > Online Product Documentation > Table of Contents > Overview of the XSLT Mapper
The XSLT mapper helps you compose XSLT that aggregates data from one or more source documents, regardless of their origin or XML. For example, an inventory application might use information from multiple vendors, each of whom organizes invoices in a different way. You can use the XSLT mapper to identify source documents, map the relevant nodes from each to a target document, and in doing that define any required XSLT instructions, XPath or Java functions, and logical operators graphically.
To use the XSLT mapper to create an XSLT stylesheet, you start by specifying one or more source documents and one target document.
The Mapper tab consists of these areas:
As you link elements and define XSLT instruction and function blocks in the mapper, Stylus Studio composes XSLT for you, which is visible (and editable) any time you click the XSLT editor's XSLT Source tab. When you have finished mapping, you can apply the stylesheet to XML documents that have the same schema as the source document. The result document also has the same schema as the destination document.
As with the
XSLT Source tab, you can preview XSLT results from the
Mapper tab by clicking the
Preview Result button (
). Debugging, however, can be performed from the
XSLT Source tab only.
This section covers the following topics:
Suppose you open the XML mapper and select
books.xml as the source document and
catalog.xml as the target document. You then map elements in the
books.xml document or structure to elements in the
catalog.xml document or structure. The result is a stylesheet that you can apply to
books.xml and to other files that have a structure similar to that of
books.xml. When you apply this stylesheet, the result is an XML document whose structure is consistent with that of
catalog.xml.
Now suppose you want to apply a stylesheet to
catalog.xml and output an XML file that has a structure similar to
books.xml. To do this, you must use the XSLT mapper to create a second stylesheet. This time,
catalog.xml is the source document and
books.xml is the destination document. The result of this mapping is a stylesheet that you can apply to documents that have a structure similar to that of
catalog.xml.
The XSLT mapper has graphical support for
Using special symbols, called blocks, you can quickly and easily create complex XSLT without writing any code, as shown in Figure 215:
Blocks can be created
xsl:for-each instruction block in the mapper.
See Working with XSLT Instructions in XSLT Mapper and Processing Source Nodes to learn more about working with blocks in the XSLT mapper.
There are a few options you can set that affect the XSLT stylesheets generated by the XSLT mapper. To display the Options dialog box, in the Stylus Studio tool bar, select Tools > Options.
Under Module Settings > XSLT Editor, click Mapper. The mapper has an option that determines whether Stylus Studio creates empty elements for unlinked nodes when the associated schema specifies that the elements are required. You might want to select this option to help ensure that your XSLT generates valid XML by ensuring that all required elements are accounted for.
Among other options under the XSLT Editor heading, consider clicking XSLT Settings and specifying whether or not you want Stylus Studio to save scenario metainformation in the stylesheet. Scenario metainformation includes anything specified in the Scenario Properties dialog box - source and output URLs, parameter values, post-processing options, and so on.
|
Note
|
|
If you select this option, Stylus Studio also saves mapper metainformation in the stylesheet; mapper metainformation includes the names of source files, node mapping information, and so on. |
If you choose not to save scenario metainformation in the stylesheet, and if the stylesheet belongs to a project, Stylus Studio saves mapper metainformation in the project. If the stylesheet does not belong to a project, and you choose not to save metainformation in the stylesheet, mapping metainformation is not saved.
Stylus Studio cannot automatically generate a stylesheet that will always generate a valid XML document. As defined by the W3C, an XML document is considered to be valid if it conforms to the DTD with which it is associated.
For example, consider a stylesheet that has required attributes. In order to specify meaningful values for them, you need to have insight as to the semantics of the operation the stylesheet is performing, and it is difficult for any application to infer this type of information. Always check to see that the stylesheets you create using the XSLT mapper generate valid input.
Stylus Studio displays the XSLT editor with the Mapper tab selected.
*) in the numeric key pad to expand the schema tree.
|
Tip
|
|
Consider working through the source document in document order as you map source and target elements. |
Each of these steps is described in greater detail in the following sections.