[m-rev.] For review: Convert Mercury terms to XML

Ian MacLarty maclarty at cs.mu.OZ.AU
Mon Dec 6 18:13:25 AEDT 2004


I've changed the xul_tree.xsl stylesheet so it can print the term paths with
arguments numbers or with field names if present.  By default the field name
version is hidden, but can be activated with the column headings drop down
menu.

I've also hidden the depth column by default, set a default size for the
window (otherwise it appears very small) and used the same xslt rule for the 
builtin types.

This is the relative diff:

@@ -12,6 +12,8 @@
 <xsl:template match="/" priority="200">
 	<xsl:element name="window">
 		<xsl:attribute name="title">Nodes</xsl:attribute>
+		<xsl:attribute name="height">500</xsl:attribute>
+		<xsl:attribute name="width">600</xsl:attribute>
 		<xsl:attribute name="xmlns">http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul</xsl:attribute>
 		<xsl:element name="tree">
 			<xsl:attribute name="flex">1</xsl:attribute>
@@ -46,6 +48,7 @@
 					<xsl:attribute name="id">depth</xsl:attribute>
 					<xsl:attribute name="label">Depth</xsl:attribute>
 					<xsl:attribute name="flex">1</xsl:attribute>
+					<xsl:attribute name="hidden">true</xsl:attribute>
 				</xsl:element>
 				<xsl:element name="splitter">
 					<xsl:attribute name="class">tree-splitter</xsl:attribute>
@@ -55,6 +58,15 @@
 					<xsl:attribute name="label">Term Path</xsl:attribute>
 					<xsl:attribute name="flex">1</xsl:attribute>
 				</xsl:element>
+				<xsl:element name="splitter">
+					<xsl:attribute name="class">tree-splitter</xsl:attribute>
+				</xsl:element>
+				<xsl:element name="treecol">
+					<xsl:attribute name="id">fieldtermpath</xsl:attribute>
+					<xsl:attribute name="label">Term Path (with field names)</xsl:attribute>
+					<xsl:attribute name="flex">1</xsl:attribute>
+					<xsl:attribute name="hidden">true</xsl:attribute>
+				</xsl:element>
 			</xsl:element>
 			<xsl:element name="treechildren">
 				<xsl:apply-templates />
@@ -62,13 +74,21 @@
 		</xsl:element>
 	</xsl:element>
 </xsl:template>
-<xsl:template match="String" priority="50">
+<xsl:template match="String|Int|Float|Char" priority="50">
 	<xsl:param name="depth">0</xsl:param>
 	<xsl:param name="termpath" />
+	<xsl:param name="fieldtermpath" />
 	<xsl:element name="treeitem">
 		<xsl:element name="treerow">
 			<xsl:element name="treecell">
-				<xsl:attribute name="label">"<xsl:value-of select="." />"</xsl:attribute>
+				<xsl:choose>
+					<xsl:when test="@name='String'">
+						<xsl:attribute name="label">"<xsl:value-of select="." />"</xsl:attribute>
+					</xsl:when>
+					<xsl:otherwise>
+						<xsl:attribute name="label"><xsl:value-of select="." /></xsl:attribute>
+					</xsl:otherwise>
+				</xsl:choose>
 			</xsl:element>
 			<xsl:element name="treecell">
 				<xsl:attribute name="label">
@@ -85,107 +105,15 @@
 			</xsl:element>
 			<xsl:element name="treecell">
 				<xsl:attribute name="label">
-					<xsl:call-template name="showpos">
-						<xsl:with-param name="termpath"><xsl:value-of select="$termpath" /></xsl:with-param>
-					</xsl:call-template>
-				</xsl:attribute>
-			</xsl:element>
-		</xsl:element>
-	</xsl:element>
-</xsl:template>
-<xsl:template match="Int" priority="50">
-	<xsl:param name="depth">0</xsl:param>
-	<xsl:param name="termpath" />
-	<xsl:element name="treeitem">
-		<xsl:element name="treerow">
-			<xsl:element name="treecell">
-				<xsl:attribute name="label">
-					<xsl:value-of select="." />
-				</xsl:attribute>
-			</xsl:element>
-			<xsl:element name="treecell">
-				<xsl:attribute name="label">
-					<xsl:value-of select="@field" />
-				</xsl:attribute>
-			</xsl:element>
-			<xsl:element name="treecell">
-				<xsl:attribute name="label">int</xsl:attribute>
-			</xsl:element>
-			<xsl:element name="treecell">
-				<xsl:attribute name="label">
-					<xsl:value-of select="$depth" />
-				</xsl:attribute>
-			</xsl:element>
-			<xsl:element name="treecell">
-				<xsl:attribute name="label">
-					<xsl:call-template name="showpos">
-						<xsl:with-param name="termpath"><xsl:value-of select="$termpath" /></xsl:with-param>
-					</xsl:call-template>
-				</xsl:attribute>
-			</xsl:element>
-		</xsl:element>
-	</xsl:element>
-</xsl:template>
-<xsl:template match="Char" priority="50">
-	<xsl:param name="depth">0</xsl:param>
-	<xsl:param name="termpath" />
-	<xsl:element name="treeitem">
-		<xsl:element name="treerow">
-			<xsl:element name="treecell">
-				<xsl:attribute name="label">
-					<xsl:value-of select="." />
-				</xsl:attribute>
-			</xsl:element>
-			<xsl:element name="treecell">
-				<xsl:attribute name="label">
-					<xsl:value-of select="@field" />
-				</xsl:attribute>
-			</xsl:element>
-			<xsl:element name="treecell">
-				<xsl:attribute name="label">character</xsl:attribute>
-			</xsl:element>
-			<xsl:element name="treecell">
-				<xsl:attribute name="label">
-					<xsl:value-of select="$depth" />
-				</xsl:attribute>
-			</xsl:element>
-			<xsl:element name="treecell">
-				<xsl:attribute name="label">
-					<xsl:call-template name="showpos">
+					<xsl:call-template name="showpath">
 						<xsl:with-param name="termpath"><xsl:value-of select="$termpath" /></xsl:with-param>
 					</xsl:call-template>
 				</xsl:attribute>
 			</xsl:element>
-		</xsl:element>
-	</xsl:element>
-</xsl:template>
-<xsl:template match="Float" priority="50">
-	<xsl:param name="depth">0</xsl:param>
-	<xsl:param name="termpath" />
-	<xsl:element name="treeitem">
-		<xsl:element name="treerow">
-			<xsl:element name="treecell">
-				<xsl:attribute name="label">
-					<xsl:value-of select="." />
-				</xsl:attribute>
-			</xsl:element>
-			<xsl:element name="treecell">
-				<xsl:attribute name="label">
-					<xsl:value-of select="@field" />
-				</xsl:attribute>
-			</xsl:element>
-			<xsl:element name="treecell">
-				<xsl:attribute name="label">float</xsl:attribute>
-			</xsl:element>
-			<xsl:element name="treecell">
-				<xsl:attribute name="label">
-					<xsl:value-of select="$depth" />
-				</xsl:attribute>
-			</xsl:element>
 			<xsl:element name="treecell">
 				<xsl:attribute name="label">
-					<xsl:call-template name="showpos">
-						<xsl:with-param name="termpath"><xsl:value-of select="$termpath" /></xsl:with-param>
+					<xsl:call-template name="showfieldpath">
+						<xsl:with-param name="fieldtermpath"><xsl:value-of select="$fieldtermpath" /></xsl:with-param>
 					</xsl:call-template>
 				</xsl:attribute>
 			</xsl:element>
@@ -195,6 +123,7 @@
 <xsl:template match="*" priority="10">
 	<xsl:param name="depth">0</xsl:param>
 	<xsl:param name="termpath" />
+	<xsl:param name="fieldtermpath" />
 	<xsl:choose>
 	<xsl:when test="parent::*[@functor='[|]'] and @functor='[|]'">
 		<xsl:if test="count(child::*) != 0">
@@ -243,11 +172,18 @@
 			</xsl:element>
 			<xsl:element name="treecell">
 				<xsl:attribute name="label">
-					<xsl:call-template name="showpos">
+					<xsl:call-template name="showpath">
 						<xsl:with-param name="termpath"><xsl:value-of select="$termpath" /></xsl:with-param>
 					</xsl:call-template>
 				</xsl:attribute>
 			</xsl:element>
+			<xsl:element name="treecell">
+				<xsl:attribute name="label">
+					<xsl:call-template name="showfieldpath">
+						<xsl:with-param name="fieldtermpath"><xsl:value-of select="$fieldtermpath" /></xsl:with-param>
+					</xsl:call-template>
+				</xsl:attribute>
+			</xsl:element>
 		</xsl:element>
 		<xsl:if test="count(child::*) != 0">
 			<xsl:element name="treechildren">
@@ -258,6 +194,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:element>
 		</xsl:if>
@@ -265,7 +213,7 @@
 	</xsl:otherwise>
 	</xsl:choose>
 </xsl:template>
-<xsl:template name="showpos">
+<xsl:template name="showpath">
 	<xsl:param name="termpath" />
 	<xsl:choose>
 	<xsl:when test="ancestor::*">
@@ -276,4 +224,22 @@
 	</xsl:otherwise>
 	</xsl:choose>
 </xsl:template>
+<xsl:template name="showfieldpath">
+	<xsl:param name="termpath" />
+	<xsl:choose>
+	<xsl:when 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:when>
+	<xsl:otherwise>
+		<xsl:value-of select="'/'" />
+	</xsl:otherwise>
+	</xsl:choose>
+</xsl:template>
 </xsl:stylesheet>
--------------------------------------------------------------------------
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