Friday, August 22, 2008

Some sample templates for use with LexEv

If your XML has been parsed using LexEv, here are some sample templates for handling the LexEv markup.

To output an entity reference:



<xsl:template match="lexev:entity">
<xsl:value-of disable-output-escaping="yes" select="concat('&amp;', @name, ';')"/>
</xsl:template>



To process a CDATA section as markup:


<xsl:template match="lexev:cdata">
<xsl:apply-templates/>
</xsl:template>


To output a DOCTYPE from the processing instructions:

In XSLT 1.0 the doctype-public and doctype-system attributes on xsl:output are static and need to be known at compile time, which means I'm afraid you have to do this:


<xsl:template match="/">
<xsl:value-of disable-output-escaping="yes"
select="concat('&lt;!DOCTYPE ', name(/*), '&#xa; PUBLIC &quot;',
processing-instruction('doctype-public'), '&quot; &quot;',
processing-instruction('doctype-system'), '&quot;&gt;')"/>
<xsl:apply-templates/>
</xsl:template>


In XSLT 2.0 you can use xsl:result-document where the doctype-public and doctype-system are AVTs which mean their values can be determined at runtime:


<xsl:template match="/">
<xsl:result-document
doctype-public="{processing-instruction('doctype-public')}"
doctype-system="{processing-instruction('doctype-system')}">
<xsl:apply-templates/>
</xsl:result-document>
</xsl:template>

1 comment:

Del Machina said...

your blog is great. your blog's title graphic is almost great, except that the xslt text is lost in the lion's head. a nit? maybe, but quite fixable. change the 'xslt' to white and move the text so that the dark lion head is entirely behind it, for example. people do judge books by their cover...