O'Reilly logo

XSLT Cookbook by Sal Mangano

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Generating Pretty Printers

Problem

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

Solution

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="http://www.w3.org/1999/XSL/Transform"> <!-- 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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required