xmlchar is an XSLT library that provides XML elements for all of the special characters defined in HTML 4.
HTML provides many named character entities, such as " " for non-breaking spaces. XML provides very few, unless you define them in a DTD or in the XML document's local DTD subset. This is inconvenient when you just want to use well-formed XML, without any need for a DTD or DOCTYPE declaration.
The xmlchar stylesheets allow you to write "<ch:nbsp/>" for a non-breaking space, for example, so that if you know the HTML name, you know the xmlchar name.
Elements are the natural way to define names for special characters in XML, but they do have the limitation that they can only be used in element content. You cannot use xmlchar elements in attribute values.
The easiest way is just to use <xsl:import>
to call
htm4-all.xsl
from within your own stylesheet. This will
convert the xmlchar elements into the correct
character entities. For example,
<html xmlns:ch="http://xmlchar.sf.net/ns#"> <body> <p>My sandwich cost <ch:pound/>2.</p> <p>Really?<ch:nbsp/> You were cheated.<ch:nbsp/> My sandwich only cost <ch:euro/>2.</p> </body> </html>is converted to
<html> <body> <p>My sandwich cost £2.</p> <p>Really? You were cheated. My sandwich only cost €2.</p> </body> </html>
where the correct HTML entities have been inserted. See the examples which come with the stylesheets for details.
xmlchar is available from SourceForge, and is released under the Lesser GNU Public License, version 2.1.