Generating Test Files with Element and Type Substitutions

It is possible in the XSLT editor to perform element and type substitutions based on derived types and substitution groups defined in the XSD. Many schemas contain abstract elements or types that can be overloaded with elements from substitution groups or elements from derived types using xsi:type.

The test tool in the XSLT editor does not currently support generation of input XML documents that contain substituted elements. So, when you invoke an XSLT map where substitutions have been made in the source tree, the following warning occurs.

Warning message

The user then has to modify the input document generated or provide their own test input document. This can become problematic, as the user must make the substitutions themselves in the input document with the correct syntax for the xsi:type definition or element substitution needed. This can be more problematic in large schemas where multiple substitutions have been made.

Using the XSLT editor, we can generate an input document that contains the correctly substituted elements with all of the appropriate namespaces/prefixes defined for us. This will provide us with a template for the input test document.

In the mapping above there are two substitutions done in the source tree. The first is a substituted element CommentList from a substitution group defined the schema document. The second is an Item type substitution for a derived item type defined in the schema document.

We would like to write a small XSLT map that will generate a document we can use as a test input file for testing this map. It has to contain the correct xsi:type and element substitution information defined in our source document.

We create a new map, selecting no schema document for the source and selecting the PurchaseOrder schema for the target, as we want to output a PurchaseOrder document we can use as test input for the PurchaseOrder source in our existing map.

By using Add Child From Schema and performing the same substitutions on the PurchaseOrder target that we have on our PurchaseOrder source, we can create a map that looks like the following:

sample map

We then execute this XSLT with the test tool to create our PurchaseOrder template document.

Test XSL Map dialog

This generates a template for our test input document with the correct substitutions for our test.

Generated template

Appropriate test data can then be entered in the fields defined. Alternatively, you can define data values in the XSLT that generates the test file to pre-populate the test file.