XSLT and entities are incompatible things: entities are expanded before running XSLT. Several methods are proposed to retain entities during XSLT processing. One of them is the following.
Each entity is represented by an element in some namespace and with the same local name as the entity name.
Example 16. Representing entities by elements
<?xml version="1.0"?> <book xmlns:entity="http://xsieve.sourceforge.net/entity"> <title>A small book</title> <entity:chapter1/> <entity:chapter2/> </book>
XSieve uses an extended SXML format that supports entities. The following XSieve program replaces the entity placeholders with the real entities.
Example 17. Converting placeholders to entities
<x:stylesheet xmlns:x = "http://www.w3.org/1999/XSL/Transform" xmlns:s = "http://xsieve.sourceforge.net" xmlns:entity = "http://xsieve.sourceforge.net/entity" extension-element-prefixes="s" version = "1.0"> <!-- --> <x:template match="@*|node()"> <x:copy> <x:apply-templates select="@*|node()"/> </x:copy> </x:template> <x:template match="entity:*"> <s:scheme> (list '& (x:eval "local-name()")) </s:scheme> </x:template> </x:stylesheet>
Applying the program to the sample XML file gives the expected result.