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 Message-Handling Stub Code

Problem

You want to generate the skeleton of your message handlers.

Solution

The following stylesheet creates a simple skeleton that takes a process name and generates stub code:

<?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.1" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="text"/> <!-- Specifies which process to generate handlers for --> <xsl:param name="process"/> <!-- Specifies which message to generate handlers for. A special value of %ALL% signifies all messages --> <xsl:param name="message" select=" '%ALL%' "/> <!-- The directory where --> <xsl:variable name="message-dir" select=" 'messages' "/> <xsl:variable name="directory-sep" select=" '/' "/> <xsl:variable name="include-ext" select=" '.h' "/> <xsl:template match="MessageRepository"> <xsl:choose> <xsl:when test="$message='%ALL%'" > <xsl:apply-templates select="Messages/Message[Receivers/ProcessRef = $process]"/> </xsl:when> <xsl:otherwise> <xsl:apply-templates select="Messages/Message[Receivers/ProcessRef = $process and Name=$message]"/> </xsl:otherwise> </xsl:choose> </xsl:template> <xsl:template match="Message" > <xsl:document href="{concat(Name,'.h')}"> <xsl:call-template name="makeHeader"/> </xsl:document> <xsl:document href="{concat(Name,'.cpp')}"> <xsl:call-template name="makeSource"/> </xsl:document> </xsl:template> <xsl:template name="makeHeader"> #ifndef <xsl:value-of select="Name"/>_h #define <xsl:value-of select="Name"/>_h #include ...

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