using xslproc to output not well formed xml
After few attempt with cduce, in the end I resorted to xslt to convert the cduce manual to a more drupal-friendly format.
Drupal uses the geshi filter to do syntax highlighting. The problem with this filter is that it does not understand CDATA sections and its input is not well-formed xml.
The cduce manual is written in a well-formed xml and uses CDATA sections for cduce code. For example:
<sample><![CDATA[
let f (x : Int) : Int = g x
let g (x : Int) : Int = x + 1
]]></sample>
My problem was to remove the cdata declaration and output something of the form:
<blockcode>
let f (x : Int) : Int = g x
let g (x : Int) : Int = x + 1
</blockcode>
After a bit of document reading and research this was my solution:
<xsl:template name="normalize">
<xsl:param name="input"/>
<xsl:param name="mode">normal</xsl:param>
<xsl:choose>
<xsl:when test="$mode = 'escape'">
<xsl:value-of disable-output-escaping="yes" select="$input"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$input"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
This template is effectively a function that is invoked with two parameters input and mode.
Input contains the text to be printed, while the mode is a boolean to
decide whether to encode the input or not. Using <xsl:copy-of ...
or xsl:text...
with disable-output-escaping does not give
the same result.
I’m not sure if this is a bug/feature or xsltproc or something written in the xslt standard.
The function to invoke the above function is as follows:
<xsl:template match="sample">
<blockcode lang="ocaml">
<xsl:call-template name="normalize">
<xsl:with-param name="input">
<xsl:value-of select="."/>
</xsl:with-param>
<xsl:with-param name="mode">escape</xsl:with-param>
</xsl:call-template>
</blockcode>
</xsl:template>