XML Word Printer for Microsoft Dynamics AX (Axapta)

1. Application Area

XML Printer solution provides an alternative way to generate Microsoft Dynamics AX (Axapta) reports in Microsoft Word format.

2. Prerequisites

  • Microsoft Word 2003.
  • Microsoft Word 2003 XSLT Inference Tool.

3. Background

XML is a standard technology for data exchange between various platforms and applications. General idea of XML Printer is to generate XML files based on data sources used in Microsoft Dynamics AX (Axapta) reports. Automatically generated XML files can be used as data sources for Microsoft Word templates that allow utilizing XML Printer together with predefined Microsoft Word templates and getting Microsoft Word document from Microsoft Dynamics AX (Axapta) report as final result.

XML Printer functionality includes 2 main parts:

  • Generate Microsoft Word template based on proper XSD schema that is to be created to use XML Printer as Word Printer.
  • Convert Microsoft Word template into XSL transformation using special Microsoft Word 2003 XSLT Inference tool.

4. Workflow

4.1. Generation of XML file with data based on Microsoft Dynamics AX (Axapta) report

XML Printer works as usual Microsoft Dynamics AX (Axapta) printer. E.g. it is necessary to redirect output of Microsoft Dynamics AX (Axapta) report into XML Printer. As a result, XML file with all data used in report will be generated. Using button “Printer setup” in posting routine (like Quotation / PackingSlip / Invoice posting) or button “Options” in report dialog, it is necessary to select XML Printer and specify a file name for newly generated XML file, as shown in Figure 1.

Figure 1: XML Printer settings

This step can be skipped if XSD schema (see chapter 4.2) is created manually.

4.2. Generation of XSD schema from XML file

Using XML Schema Definition tool (XSD.exe) from Microsoft .NET Framework tools, it is possible to generate XML schema that can be used to create Microsoft Word template.

The following link describes how to use this utility:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cptools/html/cpconxmlschemadefinitiontoolxsdexe.asp

4.3. Creation of Microsoft Word template from XSD schema

Microsoft Word template with references to XSD elements is to be created at this step. As a template is created in Microsoft Word, it allows keeping maximum formatting features in final document.

Using “Tools => Templates and Add-Ins” menu of Microsoft Word 2003, tab “XML Schema => Add Schema”, it is necessary to link XSD schema created in par. 4.2 with Microsoft Word template, as shown in Figure 2.

Figure 2: Linking Microsoft Word template and XSD schema

After XSD schema has been attached, it is possible to insert XML elements in Microsoft Word template, as shown in Figure 3.

Figure 3: Example of Microsoft Word template with XML elements

When final document is generated, these XML elements are replaced by real data from Microsoft Dynamics AX (Axapta) report.

4.4. Generation of XSL transformation from Microsoft Word template

Using Microsoft Office Word 2003 XSLT Inference Tool, it is necessary to create XSL transformation from previously created Microsoft Word template. XSL transformation helps to transform XML files into documents with complex and rich formatting quickly.

To get XSL transformation file, the following steps are necessary:

  • Save Microsoft Word template as XML (“File => Save As => XML document”). Flags “Apply transform” and “Save only data” are to be unchecked, as shown in Figure 4.
  • Use saved XML template as parameter for utility “wml2xslt.exe”, e.g. “wml2xslt.exe quotationreport.xml”.

Figure 4: Saving Microsoft Word template in XML format

As a result, XSL transformation “quotationreport.xsl” is created.

Details about this utility can be found at:

http://www.microsoft.com/downloads/details.aspx?FamilyId=2CB5B04E-61D9-4F16-9B18-223EC626080E&displaylang=en

4.5. Generation of Microsoft Word document from Microsoft Dynamics AX (Axapta) report

At this step, it is expected that template in XSL transformation format exists in \Appl\Standard\WordTemplates folder. The value of report property “Caption” is used to link XML file with report data and XSL template. E.g. if we output report “SalesQuotation” to XML Printer, it is necessary to store XSL template as “\Appl\Standard\WordTemplates\QuotationReport.xsl”. In this case, generated unicode XML file “Appl\Standard\WordReports\_quotation.xml” will be opened in Microsoft Word and automatically transformed into Microsoft Word document according to XSL transformation file.

5. Conclusion

XML Printer allows generating Microsoft Dynamics AX (Axapta) reports in Microsoft Word format without additional programming. It keeps maximum formatting features in final document, providing the output with high performance.