mirror of
https://github.com/Mercury-Language/mercury.git
synced 2026-04-15 09:23:44 +00:00
Estimated hours taken: 60 Branches: main Add library module to convert Mercury terms to XML documents and generate DTDs for Mercury types. There is a natural mapping from Mercury terms to XML documents since both are tree structures. Each functor of a Mercury type is mapped to an element name in the XML document. Extra information such as the original functor name, type and field name are stored as attribute values. Once a Mercury term is in XML it can be converted to many different formats using the appropriate stylesheet. For example it could be converted to HTML for a web server or converted to XUL to generate user interface components. The advantage of this approach is that once the appropriate stylesheet has been set up, generating HTML, XUL, MusicXML or whatever is as easy as generating a Mercury term. This library will be used to create a graphical term browser for mdb and possibly browsable HLDS dumps. extras/xml_stylesheets/README extras/xml_stylesheets/mercury_term.xsl extras/xml_stylesheets/xul_tree.xsl Some example stylesheets. One to convert XML generate with the to_xml library to a Mercury term and one to generate a XUL term browser for viewing with Mozilla or Firefox. library/library.m Add to_xml. library/to_xml.m The to_xml module with predicates for generating XML for Mercury terms and DTDs for Mercury types. tests/hard_coded/Mmakefile tests/hard_coded/write_xml.exp tests/hard_coded/write_xml.m Test to_xml predicates.
66 lines
2.0 KiB
XML
66 lines
2.0 KiB
XML
<?xml version="1.0"?>
|
|
<xsl:stylesheet version="1.0"
|
|
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
|
|
xmlns="http://www.w3.org/TR/xhtml1/strict">
|
|
<!--
|
|
This template produces a Mercury term from an xml document
|
|
generated using term_to_xml.write_xml_doc/6. The term is suitable for
|
|
reading into a Mercury program using io.read/3.
|
|
-->
|
|
<xsl:output method="text" indent="no" media-type="text/plain" />
|
|
<xsl:template match="text()" priority="100">
|
|
</xsl:template>
|
|
<xsl:template match="/" priority="200">
|
|
<xsl:apply-templates />
|
|
<xsl:text>. </xsl:text>
|
|
</xsl:template>
|
|
<xsl:template match="String" priority="50">
|
|
<xsl:text>"</xsl:text>
|
|
<xsl:value-of select="." disable-output-escaping="yes" />
|
|
<xsl:text>"</xsl:text>
|
|
<xsl:if test="following-sibling::*">
|
|
<xsl:text>,</xsl:text>
|
|
</xsl:if>
|
|
</xsl:template>
|
|
<xsl:template match="Int" priority="50">
|
|
<xsl:value-of select="." disable-output-escaping="yes" />
|
|
<xsl:if test="following-sibling::*">
|
|
<xsl:text>,</xsl:text>
|
|
</xsl:if>
|
|
</xsl:template>
|
|
<xsl:template match="Float" priority="50">
|
|
<xsl:value-of select="." disable-output-escaping="yes" />
|
|
<xsl:if test="following-sibling::*">
|
|
<xsl:text>,</xsl:text>
|
|
</xsl:if>
|
|
</xsl:template>
|
|
<xsl:template match="Char" priority="50">
|
|
<xsl:text>('</xsl:text>
|
|
<xsl:value-of select="." disable-output-escaping="yes" />
|
|
<xsl:text>')</xsl:text>
|
|
<xsl:if test="following-sibling::*">
|
|
<xsl:text>,</xsl:text>
|
|
</xsl:if>
|
|
</xsl:template>
|
|
<xsl:template match="*" priority="10">
|
|
<xsl:choose>
|
|
<xsl:when test="@functor">
|
|
<xsl:text>'</xsl:text>
|
|
<xsl:value-of select="@functor" disable-output-escaping="yes" />
|
|
<xsl:text>'</xsl:text>
|
|
</xsl:when>
|
|
<xsl:otherwise>
|
|
<xsl:value-of select="name()" disable-output-escaping="yes" />
|
|
</xsl:otherwise>
|
|
</xsl:choose>
|
|
<xsl:if test="count(child::*) != 0">
|
|
<xsl:text>(</xsl:text>
|
|
<xsl:apply-templates />
|
|
<xsl:text>)</xsl:text>
|
|
</xsl:if>
|
|
<xsl:if test="following-sibling::*">
|
|
<xsl:text>,</xsl:text>
|
|
</xsl:if>
|
|
</xsl:template>
|
|
</xsl:stylesheet>
|