Tools for escaping XML to a form renderable in XML. There are three stylesheets here, all XSLT 2.0.
Most of the documentation is in Oxygen's XD format embedded in the stylesheets. This is just a summary:
<xsl:apply-templates select="my-interesting-node" mode="verbatim"/>
The base stylesheet - lib/verbatim-base.xsl
- escapes XML to text. The only meaningful formatting options relate to the inclusion of line breaks and indentation.
<foo name="bar"/>
<foo name="bar"/>
The xhtml stylesheet - verbatim-xhtml.xsl
- escapes XML to XHTML. This allows formatting!
<foo name="bar"/>
<span class="verbatim-element"><<span class="verbatim-element-name">foo</span> <span class="verbatim-attr-name">name</span>="<span class="verbatim-attr-content">bar</span>"/><br/></span>
All parameters can be set on a global or per application basis. The global parameters are all of the form verbatim:x
. The local versions simply omit the namespace.
e.g
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:verbatim="http://www.corbas.co.uk/ns/verbatim">
<xsl:import href="verbatim-xhtml.xsl"/>
<xsl:param name="verbatim:indent-elements" select="true()"/>
<xsl:template match="example">
<xsl:apply-templates select="section" mode="verbatim"/>
</xsl:apply-templates>
</xsl:stylesheet>
or
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:verbatim="http://www.corbas.co.uk/ns/verbatim">
<xsl:import href="verbatim-xhtml.xsl"/>
<xsl:template match="example">
<xsl:apply-templates select="section" mode="verbatim">
<xsl:param name="indent-elements" select="true()"/>
</xsl:apply-templates>
</xsl:apply-templates>
</xsl:stylesheet>
The third stylesheet - verbatim-highlight-xhtml.xsl
- layers on top of the previous stylesheet to provide highlighting in the output:
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:verbatim="http://www.corbas.co.uk/ns/verbatim">
<xsl:import href="verbatim-highlight-xhtml.xsl"/>
<xsl:template match="example">
<xsl:apply-templates select="section" mode="verbatim">
<xsl:param name="indent-elements" select="true()"/>
<xsl:param name="">
</xsl:apply-templates>
</xsl:apply-templates>
</xsl:stylesheet>
The final stylesheet - verbatim-fo.xsl
- layers on top of verbatim-base.xsl
to generate XSL-FO renderings. Apart from the output (and some specific styling options), this is identical:
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:verbatim="http://www.corbas.co.uk/ns/verbatim">
<xsl:import href="verbatim-fo.xsl"/>
<xsl:param name="verbatim:indent-elements" select="true()"/>
<xsl:template match="example">
<xsl:apply-templates select="section" mode="verbatim"/>
</xsl:apply-templates>
</xsl:stylesheet>