Working with XML Solutions

As you see from the simple ContactML XML schema presented earlier in this chapter, rigorous control of the data types, structure, and content arrangement is a key requirement of working in XML. We've discussed previously how Word's integration with XML also provides great flexibility. This flexibility is provided in part by XML Solutions.

Understanding XML Solutions

In Word an XML Solution is an XSLT Transformation that is linked to a specific XML schema. This capability allows you to keep one set of data in an XML structure and link transformations representing different purposes of the data. When a new purpose (or solution) is identified, a new transformation can be added to the schema without having to move around any data.

Managing XML Solutions in the Schema Library

XML Solutions in Word are managed from within the Schema Library. To access the Schema Library, select the Tools, Templates and Add-Ins menu, click the XML Schema tab, and then click the Schema Library button. XML Solutions are managed in the bottom half of this dialog (see Figure 25.33).

Figure 25.33. Managing XML Solutions in the Schema Library.


Follow these steps to add a solution:

  1. In the Select a Schema list, click on the schema to which the solution will be added.

  2. Click the Add Solution button. The Add Solution dialog is displayed (see Figure 25.34).

    Figure 25.34. The Add Solution dialog.


  3. Navigate to the XSLT transformation file (.xsl) and click Open. The Solution Settings dialog is displayed (see Figure 25.35).

    Figure 25.35. The Solution Settings dialog.


  4. Enter an alias name to identify the solution and click OK. The added solution will be displayed in the Select a Solution list. If this is the first solution to be added, it will also show up in the Default Solution selection.

To modify the solution settings, select the solution in the Select a Solution list and click the Solution Settings button. You can modify the alias name, change the path to the transformation file, or control whether this change affects all users (see Figure 25.35).

To delete a solution, select the solution in the Select a Solution list and click the Delete Solution button.

If you have multiple solutions attached to a schema, you can change the default solution using the Default Solution drop-down list.

After you have completed your changes to the Solutions, click OK to dismiss the dialog.

Managing Your Data with XML Solutions

We now have a good picture of how to create XML data based on a schema, what XSLT transformations represent, and how to associate them with a schema. Now how can we use that information to manage our data? Remember that our primary goals are to keep data in a well-defined structure, reduce duplication of input, and support repurposing of the information that has already been captured.

Let's think about our simple contact-list example and how this might apply. We have a friendly front end to enter the information with the data being saved in XML format based on an XML schema. We can include as many contacts in our list as we want and can extract the pure data (save as data only) anytime we want. After using this document for a time, we get tired of paging through all the contact records and realize that we need a simple list of names and email addresses. In the past we probably would have created a new document and then paged through the contact list copying and pasting entries into the other document. After this new document was created we would have duplicate sources of data that have to be separately maintained.

To produce our email list using XML, we can follow these steps:

  1. Use File, Save As to create a new XML file with data only.

  2. Create an XSLT transformation file (.xsl) with the following code:

    <?xml version=" 1.0" ?>
    <xsl:stylesheet xmlns:xsl=""  version=" 1.0" 
    xmlns:cl="" >
    <xsl:template match=" /" >
        <xsl:for-each select=" cl:ContactList/cl:Contact" >
            <name><xsl:value-of select=" cl:Fullname/cl:lastname" />,
                  <xsl:value-of select=" cl:Fullname/cl:lastname" />
            <email><xsl:value-of select=" cl:email" /></email>
  3. Add the transformation file as a solution associated with the ContactML schema.

  4. Open Word, select the File, Open menu, and pick the data-only XML file. When the file is loaded, you will be presented with the list of data views that are available (see Figure 25.36).

    Figure 25.36. The email list solution for the contact list.


  5. Select the Data Only and the Email List data views to see the two listings.

    Part I: Word Basics: Get Productive Fast
    Part II: Building Slicker Documents Faster
    Part III: The Visual Word: Making Documents Look Great
    Part IV: Industrial-Strength Document Production Techniques
    Part VI: The Corporate Word