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 Data Wrappers

Problem

You want to create classes that wrap the data contained in each message with a type-safe interface.

Solution

The solution works in two modes. If a message name is provided in a parameter, then it generates a wrapper only for that message data. Otherwise, if no message is specified, it generates wrappers for all messages:

<xsl:stylesheet version="1.1" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="text"/> <xsl:strip-space elements="*"/> <!--The message to generate data for. '*' for all --> <xsl:param name="message" select=" '*' "/> <!--The directory to generate code --> <xsl:param name="generationDir" select=" 'src/' "/> <!--The C++ header extension to use --> <xsl:param name="headerExt" select=" '.h' "/> <!--The C++ source extension to use --> <xsl:param name="sourceExt" select=" '.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" /> <!-- Top level template determines which messages to process --> <xsl:template match="/"> <xsl:choose> <xsl:when test="$message = '*'"> <xsl:apply-templates select="*/Messages/*"/> </xsl:when> <xsl:when test="*/Messages/Message[Name=$message]"> <xsl:apply-templates select="*/Messages/Message[Name=$message]"/> </xsl:when> <xsl:otherwise> <xsl:message terminate="yes">No such ...

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