Generating Pretty Printers


You need tools to help debug your application. In particular, you want the ability to render binary messages in human-readable form.


When developing messaging applications, developers often hand-code pretty printers because they make debugging these applications considerably easier. However, this kind of code can be generated if you have a message repository. This solution shows how to reuse the message switch generator from Recipe 10.2:

<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE xslt [ <!--Used to control code intenting --> <!ENTITY INDENT " "> <!ENTITY INDENT2 "&INDENT;&INDENT;"> <!ENTITY LS "&lt;&lt;"> ]> <xsl:stylesheet version="1.1" xmlns:xsl=""> <!-- This pretty-printer generator needs a message switch so we --> <!-- reuse the one we already wrote. --> <xsl:import href="messageSwitch.xslt"/> <!--The directory to generate code --> <xsl:param name="generationDir" select=" 'src/' "/> <!--The C++ header file name --> <xsl:param name="prettyPrintHeader" select=" 'prettyPrint.h' "/> <!--The C++ source file name --> <xsl:param name="prettyPrintSource" select=" 'prettyPrint.C' "/> <!--Key to locate data types by name --> <xsl:key name="dataTypes" match="Structure" use="Name" /> <xsl:key name="dataTypes" match="Primitive" use="Name" /> <xsl:key name="dataTypes" match="Array" use="Name" /> <xsl:key name="dataTypes" match="Enumeration" use="Name" /> <xsl:template match="MessageRepository"> <xsl:document ...

Get XSLT Cookbook now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.