[m-rev.] for review: add a stylesheet to convert 234 trees to HTML

Ian MacLarty maclarty at cs.mu.OZ.AU
Wed Jun 29 18:05:11 AEST 2005


For review by anyone.

Estimated hours taken: 1
Branches: main

Add an XSLT style sheet to convert 234 trees to HTML tables.

Fix a bug in the XUL stylesheet.

extras/xml_stylesheets/README:
	Document the new stylesheet.

extras/xml_stylesheets/html_tree234.xsl:
	The stylesheet traverses the 234 tree in order, emitting
	HTML table rows as it goes.

extras/xml_stylesheets/xul_tree.xsl:
	Pass the fieldtermpath template parameter correctly.

Index: extras/xml_stylesheets/README
===================================================================
RCS file: /home/mercury1/repository/mercury/extras/xml_stylesheets/README,v
retrieving revision 1.1
diff -u -r1.1 README
--- extras/xml_stylesheets/README	7 Dec 2004 04:55:49 -0000	1.1
+++ extras/xml_stylesheets/README	29 Jun 2005 07:58:35 -0000
@@ -6,6 +6,9 @@
 include a reference to the stylesheet in the XML document and have your browser
 apply the stylesheet, although this only works with some browsers.

+These stylesheets can also be used with mdb's `browse --xml' command
+(see the user guide for more details on `browse --xml').
+
 mercury_term.xsl
 	Stylesheet to convert an XML document generated with
 	term_to_xml.write_xml_doc/6 back to a Mercury term suitable for reading
@@ -15,3 +18,11 @@
 	Stylesheet to convert an XML document generated with
 	term_to_xml.write_xml_doc/6 to a XUL tree structure suitable for
 	browsing with Mozilla or Firefox.
+
+html_234tree.xsl
+	Converts a 234 tree (as defined in the standard library) to an XHTML
+	table.  The paths of each key and value are also shown.  This
+	is useful for looking up values or keys in 234 trees from the
+	debugger by using the search facilities of your web browser,
+	although it's impractical for very large 234 trees and doesn't work
+	with nested 234 trees.
Index: extras/xml_stylesheets/html_tree234.xsl
===================================================================
RCS file: extras/xml_stylesheets/html_tree234.xsl
diff -N extras/xml_stylesheets/html_tree234.xsl
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ extras/xml_stylesheets/html_tree234.xsl	29 Jun 2005 07:50:20 -0000
@@ -0,0 +1,183 @@
+<?xml version="1.0"?>
+<xsl:stylesheet version="1.0"
+xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
+<!--
+	This template produces an HTML document for 234 trees.
+-->
+<xsl:strip-space elements="*" />
+<xsl:template match="/" priority="200">
+	<html>
+	<head>
+	<title>234 Tree</title>
+	</head>
+	<body>
+	<table border="1">
+	<tr>
+		<td>Key</td><td>Path</td><td>Value</td><td>Path</td>
+	</tr>
+	<xsl:apply-templates />
+	</table>
+	</body>
+	</html>
+</xsl:template>
+
+<xsl:template match="empty" priority="50">
+</xsl:template>
+
+<xsl:template match="two" priority="50">
+	<xsl:param name="termpath" />
+	<xsl:apply-templates select="*[position() = 3]" >
+		<xsl:with-param name="termpath">
+			<xsl:value-of select="concat($termpath, '/', 3)"/>
+		</xsl:with-param>
+	</xsl:apply-templates>
+	<tr>
+	<td><xsl:apply-templates select="*[position()=1]"/></td>
+	<td><xsl:value-of select="concat($termpath, '/', 1)"/></td>
+	<td><xsl:apply-templates select="*[position()=2]"/></td>
+	<td><xsl:value-of select="concat($termpath, '/', 2)"/></td>
+	</tr>
+	<xsl:apply-templates select="*[position() = 4]" >
+		<xsl:with-param name="termpath">
+			<xsl:value-of select="concat($termpath, '/', 4)"/>
+		</xsl:with-param>
+	</xsl:apply-templates>
+</xsl:template>
+<xsl:template match="three" priority="50">
+	<xsl:param name="termpath" />
+	<xsl:apply-templates select="*[position() = 5]" >
+		<xsl:with-param name="termpath">
+			<xsl:value-of select="concat($termpath, '/', 5)"/>
+		</xsl:with-param>
+	</xsl:apply-templates>
+	<tr>
+	<td><xsl:apply-templates select="*[position()=1]"/></td>
+	<td><xsl:value-of select="concat($termpath, '/', 1)"/></td>
+	<td><xsl:apply-templates select="*[position()=2]"/></td>
+	<td><xsl:value-of select="concat($termpath, '/', 2)"/></td>
+	</tr>
+	<xsl:apply-templates select="*[position() = 6]" >
+		<xsl:with-param name="termpath">
+			<xsl:value-of select="concat($termpath, '/', 6)"/>
+		</xsl:with-param>
+	</xsl:apply-templates>
+	<tr>
+	<td><xsl:apply-templates select="*[position()=3]"/></td>
+	<td><xsl:value-of select="concat($termpath, '/', 3)"/></td>
+	<td><xsl:apply-templates select="*[position()=4]"/></td>
+	<td><xsl:value-of select="concat($termpath, '/', 4)"/></td>
+	</tr>
+	<xsl:apply-templates select="*[position() = 7]" >
+		<xsl:with-param name="termpath">
+			<xsl:value-of select="concat($termpath, '/', 7)"/>
+		</xsl:with-param>
+	</xsl:apply-templates>
+</xsl:template>
+<xsl:template match="four" priority="50">
+	<xsl:param name="termpath" />
+	<xsl:apply-templates select="*[position() = 7]" >
+		<xsl:with-param name="termpath">
+			<xsl:value-of select="concat($termpath, '/', 7)"/>
+		</xsl:with-param>
+	</xsl:apply-templates>
+	<tr>
+	<td><xsl:apply-templates select="*[position()=1]"/></td>
+	<td><xsl:value-of select="concat($termpath, '/', 1)"/></td>
+	<td><xsl:apply-templates select="*[position()=2]"/></td>
+	<td><xsl:value-of select="concat($termpath, '/', 2)"/></td>
+	</tr>
+	<xsl:apply-templates select="*[position() = 8]" >
+		<xsl:with-param name="termpath">
+			<xsl:value-of select="concat($termpath, '/', 8)"/>
+		</xsl:with-param>
+	</xsl:apply-templates>
+	<tr>
+	<td><xsl:apply-templates select="*[position()=3]"/></td>
+	<td><xsl:value-of select="concat($termpath, '/', 3)"/></td>
+	<td><xsl:apply-templates select="*[position()=4]"/></td>
+	<td><xsl:value-of select="concat($termpath, '/', 4)"/></td>
+	</tr>
+	<xsl:apply-templates select="*[position() = 9]" >
+		<xsl:with-param name="termpath">
+			<xsl:value-of select="concat($termpath, '/', 9)"/>
+		</xsl:with-param>
+	</xsl:apply-templates>
+	<tr>
+	<td><xsl:apply-templates select="*[position()=5]"/></td>
+	<td><xsl:value-of select="concat($termpath, '/', 5)"/></td>
+	<td><xsl:apply-templates select="*[position()=6]"/></td>
+	<td><xsl:value-of select="concat($termpath, '/', 6)"/></td>
+	</tr>
+	<xsl:apply-templates select="*[position() = 10]" >
+		<xsl:with-param name="termpath">
+			<xsl:value-of select="concat($termpath, '/', 10)"/>
+		</xsl:with-param>
+	</xsl:apply-templates>
+</xsl:template>
+
+<xsl:template match="String" priority="50">
+	<xsl:param name="termpath" />
+	<xsl:text>"</xsl:text>
+	<xsl:value-of select="." disable-output-escaping="yes" />
+	<xsl:text>"</xsl:text>
+	<xsl:if test="following-sibling::* and not(parent::two) and not(parent::three) and not(parent::four)">
+		<xsl:text>,</xsl:text>
+	</xsl:if>
+</xsl:template>
+<xsl:template match="Int" priority="50">
+	<xsl:param name="termpath" />
+	<xsl:value-of select="." disable-output-escaping="yes" />
+	<xsl:if test="following-sibling::* and not(parent::two) and not(parent::three) and not(parent::four)">
+		<xsl:text>,</xsl:text>
+	</xsl:if>
+</xsl:template>
+<xsl:template match="Float" priority="50">
+	<xsl:param name="termpath" />
+	<xsl:value-of select="." disable-output-escaping="yes" />
+	<xsl:if test="following-sibling::* and not(parent::two) and not(parent::three) and not(parent::four)">
+		<xsl:text>,</xsl:text>
+	</xsl:if>
+</xsl:template>
+<xsl:template match="Char" priority="50">
+	<xsl:param name="termpath" />
+	<xsl:text>('</xsl:text>
+	<xsl:value-of select="." disable-output-escaping="yes" />
+	<xsl:text>')</xsl:text>
+	<xsl:if test="following-sibling::* and not(parent::two) and not(parent::three) and not(parent::four)">
+		<xsl:text>,</xsl:text>
+	</xsl:if>
+</xsl:template>
+
+<xsl:template match="*" priority="10">
+	<xsl:param name="termpath" />
+	<xsl:choose>
+	<xsl:when test="@functor">
+		<xsl:value-of select="@functor" disable-output-escaping="yes" />
+	</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::* and not(parent::two) and not(parent::three) and not(parent::four)">
+		<xsl:text>,</xsl:text>
+	</xsl:if>
+</xsl:template>
+
+<xsl:template name="showpath">
+	<xsl:param name="termpath" />
+	<xsl:choose>
+	<xsl:when test="ancestor::*">
+		<xsl:value-of select="concat($termpath, '/', position())"/>
+	</xsl:when>
+	<xsl:otherwise>
+		<xsl:value-of select="'/'" />
+	</xsl:otherwise>
+	</xsl:choose>
+</xsl:template>
+
+</xsl:stylesheet>
Index: extras/xml_stylesheets/xul_tree.xsl
===================================================================
RCS file: /home/mercury1/repository/mercury/extras/xml_stylesheets/xul_tree.xsl,v
retrieving revision 1.2
diff -u -r1.2 xul_tree.xsl
--- extras/xml_stylesheets/xul_tree.xsl	10 Dec 2004 09:44:23 -0000	1.2
+++ extras/xml_stylesheets/xul_tree.xsl	29 Jun 2005 07:56:24 -0000
@@ -135,6 +135,18 @@
 						<xsl:value-of select="concat($termpath, '/', position())"/>
 					</xsl:if>
 				</xsl:with-param>
+				<xsl:with-param name="fieldtermpath">
+					<xsl:if test="ancestor::*">
+						<xsl:choose>
+						<xsl:when test="@field">
+							<xsl:value-of select="concat($fieldtermpath, '/', @field)"/>
+						</xsl:when>
+						<xsl:otherwise>
+							<xsl:value-of select="concat($fieldtermpath, '/', position())"/>
+						</xsl:otherwise>
+						</xsl:choose>
+					</xsl:if>
+				</xsl:with-param>
 			</xsl:apply-templates>
 		</xsl:if>
 	</xsl:when>

--------------------------------------------------------------------------
mercury-reviews mailing list
post:  mercury-reviews at cs.mu.oz.au
administrative address: owner-mercury-reviews at cs.mu.oz.au
unsubscribe: Address: mercury-reviews-request at cs.mu.oz.au Message: unsubscribe
subscribe:   Address: mercury-reviews-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------



More information about the reviews mailing list