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 Switching Code

Problem

You want to generate the switching code that will route incoming messages to their message handlers.

Solution

The message repository stores information about which processes receive which messages. Therefore, given a process name, you can generate a message switch that routes inbound messages to handlers:

<?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="text"/> <xsl:param name="process" select=" '*' "/> <xsl:variable name="message-dir" select=" 'messages' "/> <xsl:variable name="directory-sep" select=" '/' "/> <xsl:variable name="include-ext" select=" '.h' "/> <xsl:template match="MessageRepository"> <!-- Generate source file preliminaries --> <xsl:call-template name="file-start"/> <!-- Generate includes for messages this process recives --> <xsl:apply-templates select="Messages/ Message[Receivers/ ProcessRef = $process or $process = '*']" mode="includes"/> <!-- Generate message switch preliminaries --> <xsl:call-template name="switch-start"/> <!-- Generate switch body --> <xsl:apply-templates select="Messages/ Message[Receivers/ ProcessRef = $process or $process = '*']" mode="switch"/> <!-- Generate switch end --> <xsl:call-template name="switch-end"/> <!-- Generate file end --> <xsl:call-template name="file-end"/> </xsl:template> <!-- Generate an include for each message --> <xsl:template match="Message" mode="includes"> <xsl:text>#include &lt;</xsl:text> ...

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