← Prev in month ← Prev in thread

Pretty printing source code

From
Norman Walsh <>
Date
2003-11-22T13:04:05+00:00
ID
Thread
Pretty printing source code
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                xmlns:h="http://www.w3.org/1999/xhtml"
		exclude-result-prefixes="h"
                version="1.0">

<xsl:output method="xml"/>

<xsl:template match="h:html">
  <xsl:apply-templates select="h:body"/>
</xsl:template>

<xsl:template match="h:head"/>

<xsl:template match="h:body">
  <article>
    <title>HTMLize to DocBook Wrapper</title>
    <xsl:apply-templates select="h:pre"/>
  </article>
</xsl:template>

<xsl:template match="h:pre">
  <programlisting>
    <xsl:apply-templates/>
  </programlisting>
</xsl:template>

<xsl:template match="h:span[@class='comment']" priority="2">
  <code role="comment">
    <xsl:apply-templates/>
  </code>    
</xsl:template>

<xsl:template match="h:span[@class='type']" priority="2">
  <type>
    <xsl:apply-templates/>
  </type>
</xsl:template>

<xsl:template match="h:span[@class='variable-name']" priority="2">
  <varname>
    <xsl:apply-templates/>
  </varname>
</xsl:template>

<xsl:template match="h:span[@class='function-name']" priority="2">
  <function>
    <xsl:apply-templates/>
  </function>
</xsl:template>

<xsl:template match="h:span[@class='constant']" priority="2">
  <constant>
    <xsl:apply-templates/>
  </constant>
</xsl:template>

<xsl:template match="h:span[@class='keyword']" priority="2">
  <code role="keyword">
    <xsl:apply-templates/>
  </code>
</xsl:template>

<xsl:template match="h:span[@class='string']" priority="2">
  <literal>
    <xsl:apply-templates/>
  </literal>
</xsl:template>

<xsl:template match="h:span[@class='underline']" priority="2">
  <emphasis role="underline">
    <xsl:apply-templates/>
  </emphasis>
</xsl:template>

<xsl:template match="h:span">
  <xsl:message>Unexpected class on span: <xsl:value-of select="@class"/></xsl:message>
  <code>
    <xsl:apply-templates/>
  </code>
</xsl:template>

<xsl:template match="h:*">
  <xsl:message>Unexpected <xsl:value-of select="local-name(.)"/></xsl:message>
  <code>
    <xsl:apply-templates/>
  </code>
</xsl:template>

</xsl:stylesheet>



                                        Be seeing you,
                                          norm

P.S. I've sent in a request to the author of htmlize to add an XHTML
option.

- -- 
Norman Walsh <>      | Unprovided with original learning,
http://www.oasis-open.org/docbook/ | unformed in the habits of
Chair, DocBook Technical Committee | thinking, unskilled in the arts of
                                   | composition, I resolved to write a
                                   | book.--Edward Gibbon
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.3 (GNU/Linux)
Comment: Processed by Mailcrypt 3.5.8 <http://mailcrypt.sourceforge.net/>

iD8DBQE/v186OyltUcwYWjsRAm/SAJ0Xz9rzo2WrbMfO+fVlsMZMn8OfowCgginP
KSun6bpCKZIBCakDFAjgzdE=
=j2t7
-----END PGP SIGNATURE-----
← Prev in month ← Prev in thread