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 ...
Get XSLT Cookbook now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.