You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucenenet.apache.org by ni...@apache.org on 2017/08/06 17:59:14 UTC

[16/33] lucenenet git commit: Lucene.Net.Benchmark: Added Sax and TagSoup to the Support folder.

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/198e5868/src/Lucene.Net.Benchmark/Support/TagSoup/stml/stml.rnc
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Benchmark/Support/TagSoup/stml/stml.rnc b/src/Lucene.Net.Benchmark/Support/TagSoup/stml/stml.rnc
new file mode 100644
index 0000000..b767640
--- /dev/null
+++ b/src/Lucene.Net.Benchmark/Support/TagSoup/stml/stml.rnc
@@ -0,0 +1,49 @@
+# This file is part of TagSoup and is Copyright 2002-2008 by John Cowan.
+#
+# TagSoup is licensed under the Apache License,
+# Version 2.0.  You may obtain a copy of this license at
+# http://www.apache.org/licenses/LICENSE-2.0 .  You may also have
+# additional legal rights not granted by this license.
+#
+# TagSoup is distributed in the hope that it will be useful, but
+# unless required by applicable law or agreed to in writing, TagSoup
+# is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS
+# OF ANY KIND, either express or implied; not even the implied warranty
+# of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+
+# State Table Markup Language
+default namespace = "http://www.ccil.org/~cowan/XML/tagsoup/stml"
+start = statetable
+
+## Root element
+statetable = element statetable {
+	attribute version {"1.0"},
+	attribute id {xsd:ID}?,
+	symbol*,
+	action+,
+	state+
+	}
+
+## A symbol specifies a non-character input to the state machine
+symbol = element symbol {
+	attribute id {xsd:ID}
+	}
+
+## An action is the name for what the state machine does
+action = element action {
+	attribute id {xsd:ID}
+	}
+
+## A state specifies an internal state of the machine
+state = element state {
+	attribute id {xsd:ID},
+	tr*
+	}
+
+## A tr specifies a state transition
+tr = element tr {
+	(attribute symbol {xsd:IDREF} |
+		attribute char {xsd:string {length = "1"}}),
+	attribute action {xsd:IDREF},
+	attribute newstate {xsd:IDREF}
+	}

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/198e5868/src/Lucene.Net.Benchmark/Support/TagSoup/stml/stml.xslt
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Benchmark/Support/TagSoup/stml/stml.xslt b/src/Lucene.Net.Benchmark/Support/TagSoup/stml/stml.xslt
new file mode 100644
index 0000000..524f998
--- /dev/null
+++ b/src/Lucene.Net.Benchmark/Support/TagSoup/stml/stml.xslt
@@ -0,0 +1,150 @@
+<!--
+// This file is part of TagSoup and is Copyright 2002-2008 by John Cowan.
+// 
+// TagSoup is licensed under the Apache License,
+// Version 2.0.  You may obtain a copy of this license at
+// http://www.apache.org/licenses/LICENSE-2.0 .  You may also have
+// additional legal rights not granted by this license.
+//
+// TagSoup is distributed in the hope that it will be useful, but
+// unless required by applicable law or agreed to in writing, TagSoup
+// is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS
+// OF ANY KIND, either express or implied; not even the implied warranty
+// of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+-->
+
+<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+	xmlns:stml="http://www.ccil.org/~cowan/XML/tagsoup/stml"
+	version="1.0">
+
+  <xsl:output method="text"/>
+
+  <xsl:strip-space elements="*"/>
+
+  <!-- The main template.  Generates declarations for states and
+       actions, then the statetable itself, and then a comment (used for
+       manual checking) listing all the actions compactly.  -->
+  <xsl:template match="stml:statetable">
+    <xsl:apply-templates select="stml:state">
+      <xsl:sort select="@id"/>
+    </xsl:apply-templates>
+
+    <xsl:apply-templates select="stml:action">
+      <xsl:sort select="@id"/>
+    </xsl:apply-templates>
+
+    <xsl:text>&#x9;private static int[] statetable = {&#xA;</xsl:text>
+    <xsl:apply-templates select="stml:state/stml:tr">
+      <xsl:sort select="../@id"/>
+      <xsl:sort select="@symbol"/>
+      <xsl:sort select="@char"/>
+    </xsl:apply-templates>
+    <xsl:text>&#xA;&#x9;};&#xA;</xsl:text>
+
+    <xsl:text>&#x9;private static readonly string[] debug_actionnames = { ""</xsl:text>
+    <xsl:apply-templates select="stml:action" mode="debug">
+      <xsl:sort select="@id"/>
+    </xsl:apply-templates>
+    <xsl:text>};&#xA;</xsl:text>
+
+    <xsl:text>&#x9;private static readonly string[] debug_statenames = { ""</xsl:text>
+    <xsl:apply-templates select="stml:state" mode="debug">
+      <xsl:sort select="@id"/>
+    </xsl:apply-templates>
+    <xsl:text>};&#xA;</xsl:text>
+
+    <xsl:text>&#xA;</xsl:text>
+  </xsl:template>
+
+  <!-- Generate a single state declaration.  -->
+  <xsl:template match="stml:state">
+    <xsl:text>&#x9;private const int </xsl:text>
+    <xsl:value-of select="@id"/>
+    <xsl:text> = </xsl:text>
+    <xsl:value-of select="position()"/>
+    <xsl:text>;&#xA;</xsl:text>
+  </xsl:template>
+
+  <!-- Generate a single action declaration.  -->
+  <xsl:template match="stml:action">
+    <xsl:text>&#x9;private const int </xsl:text>
+    <xsl:value-of select="@id"/>
+    <xsl:text> = </xsl:text>
+    <xsl:value-of select="position()"/>
+    <xsl:text>;&#xA;</xsl:text>
+  </xsl:template>
+
+  <!-- Generate a single row of the statetable.  -->
+  <xsl:template match="stml:tr">
+    <xsl:choose>
+      <xsl:when test="@symbol = 'EOF'">
+        <xsl:call-template name="dump-tr">
+          <xsl:with-param name="char" select="&quot;-1&quot;"/>
+        </xsl:call-template>
+      </xsl:when>
+      <xsl:when test="@symbol = 'LF'">
+        <xsl:call-template name="dump-tr">
+          <xsl:with-param name="char" select="&quot;'\n'&quot;"/>
+        </xsl:call-template>
+      </xsl:when>
+      <xsl:when test="@symbol = 'default'">
+        <xsl:call-template name="dump-tr">
+          <xsl:with-param name="char" select="&quot;0&quot;"/>
+        </xsl:call-template>
+      </xsl:when>
+      <xsl:when test="@char = &quot;&apos;&quot;">
+        <xsl:call-template name="dump-tr">
+          <xsl:with-param name="char" select="&quot;'\''&quot;"/>
+        </xsl:call-template>
+      </xsl:when>
+      <xsl:when test="@symbol = 'S'">
+        <xsl:call-template name="dump-tr">
+          <xsl:with-param name="char" select="&quot;' '&quot;"/>
+        </xsl:call-template>
+        <xsl:call-template name="dump-tr">
+          <xsl:with-param name="char" select="&quot;'\n'&quot;"/>
+        </xsl:call-template>
+        <xsl:call-template name="dump-tr">
+          <xsl:with-param name="char" select="&quot;'\t'&quot;"/>
+        </xsl:call-template>
+      </xsl:when>
+      <xsl:otherwise>
+        <xsl:call-template name="dump-tr">
+          <xsl:with-param name="char"
+		select="concat(&quot;'&quot;, @char, &quot;'&quot;)"/>
+        </xsl:call-template>
+      </xsl:otherwise>
+    </xsl:choose>
+  </xsl:template>
+
+  <!-- This is a subroutine used to do the actual printing. -->
+  <xsl:template name="dump-tr">
+    <xsl:param name="char"/>
+    <xsl:text>&#x9;&#x9;</xsl:text>
+    <xsl:value-of select="../@id"/>
+    <xsl:text>, </xsl:text>
+    <xsl:value-of select="$char"/>
+    <xsl:text>, </xsl:text>
+    <xsl:value-of select="@action"/>
+    <xsl:text>, </xsl:text>
+    <xsl:value-of select="@newstate"/>
+    <xsl:text>,&#xA;</xsl:text>
+  </xsl:template>
+
+  <!-- Generate a single action name in the "Actions:" comment.
+        The mode is used to keep XSLT from confusing this with the
+        regular actions template that does the action declarations.  -->
+  <xsl:template match="stml:action" mode="debug">
+    <xsl:text>, "</xsl:text>
+    <xsl:value-of select="@id"/>
+    <xsl:text>"</xsl:text>
+  </xsl:template>
+
+  <!-- Generate a single stat debug name.  -->
+  <xsl:template match="stml:state" mode="debug">
+    <xsl:text>, "</xsl:text>
+    <xsl:value-of select="@id"/>
+    <xsl:text>"</xsl:text>
+  </xsl:template>
+
+</xsl:transform>

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/198e5868/src/Lucene.Net.Benchmark/Support/TagSoup/tssl/tssl-models.xslt
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Benchmark/Support/TagSoup/tssl/tssl-models.xslt b/src/Lucene.Net.Benchmark/Support/TagSoup/tssl/tssl-models.xslt
new file mode 100644
index 0000000..7e49680
--- /dev/null
+++ b/src/Lucene.Net.Benchmark/Support/TagSoup/tssl/tssl-models.xslt
@@ -0,0 +1,47 @@
+<!-- Generate Java code to be inserted into HTMLModels.java.  -->
+
+<!--
+// This file is part of TagSoup and is Copyright 2002-2008 by John Cowan.
+// 
+// This file is part of TagSoup and is Copyright 2002-2008 by John Cowan.
+//
+// TagSoup is licensed under the Apache License,
+// Version 2.0.  You may obtain a copy of this license at
+// http://www.apache.org/licenses/LICENSE-2.0 .  You may also have
+// additional legal rights not granted by this license.
+//
+// TagSoup is distributed in the hope that it will be useful, but
+// unless required by applicable law or agreed to in writing, TagSoup
+// is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS
+// OF ANY KIND, either express or implied; not even the implied warranty
+// of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+-->
+
+<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+	xmlns:tssl="http://www.ccil.org/~cowan/XML/tagsoup/tssl"
+	version="1.0">
+
+  <xsl:output method="text"/>
+
+  <xsl:strip-space elements="*"/>
+
+  <!-- The main template.  We are going to generate Java constant
+       definitions for the groups in the file.  -->
+  <xsl:template match="tssl:schema">
+    <xsl:apply-templates select="tssl:group">
+      <xsl:sort select="@id"/>
+    </xsl:apply-templates>
+  </xsl:template>
+
+  <!-- Generate a declaration for a single group.  -->
+  <xsl:template match="tssl:group" name="tssl:group">
+    <xsl:param name="id" select="@id"/>
+    <xsl:param name="number" select="position()"/>
+    <xsl:text>&#x9;public const int </xsl:text>
+    <xsl:value-of select="$id"/>
+    <xsl:text> = 1 &lt;&lt; </xsl:text>
+    <xsl:value-of select="$number"/>
+    <xsl:text>;&#xA;</xsl:text>
+  </xsl:template>
+
+</xsl:transform>

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/198e5868/src/Lucene.Net.Benchmark/Support/TagSoup/tssl/tssl-validate.xslt
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Benchmark/Support/TagSoup/tssl/tssl-validate.xslt b/src/Lucene.Net.Benchmark/Support/TagSoup/tssl/tssl-validate.xslt
new file mode 100644
index 0000000..81faab5
--- /dev/null
+++ b/src/Lucene.Net.Benchmark/Support/TagSoup/tssl/tssl-validate.xslt
@@ -0,0 +1,40 @@
+<!-- Generate complaints if the schema is invalid in some way.  -->
+
+<!--
+// This file is part of TagSoup and is Copyright 2002-2008 by John Cowan.
+// 
+// TagSoup is licensed under the Apache License,
+// Version 2.0.  You may obtain a copy of this license at
+// http://www.apache.org/licenses/LICENSE-2.0 .  You may also have
+// additional legal rights not granted by this license.
+//
+// TagSoup is distributed in the hope that it will be useful, but
+// unless required by applicable law or agreed to in writing, TagSoup
+// is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS
+// OF ANY KIND, either express or implied; not even the implied warranty
+// of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+-->
+
+<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+	xmlns:tssl="http://www.ccil.org/~cowan/XML/tagsoup/tssl"
+	version="1.0">
+
+  <xsl:output method="text"/>
+
+  <xsl:strip-space elements="*"/>
+
+  <!-- Generates a report if an element does not belong to at least
+       one of the groups that its parent element contains.  -->
+  <xsl:template match="tssl:element/tssl:element">
+    <xsl:if test="not(tssl:memberOfAny) and not(tssl:memberOf/@group = ../tssl:contains/@group)">
+      <xsl:value-of select="@name"/>
+      <xsl:text> is not in the content model of </xsl:text>
+      <xsl:value-of select="../@name"/>
+      <xsl:text>&#xA;</xsl:text>
+    </xsl:if>
+    <xsl:apply-templates/>
+  </xsl:template>
+
+
+
+</xsl:transform>

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/198e5868/src/Lucene.Net.Benchmark/Support/TagSoup/tssl/tssl.rnc
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Benchmark/Support/TagSoup/tssl/tssl.rnc b/src/Lucene.Net.Benchmark/Support/TagSoup/tssl/tssl.rnc
new file mode 100644
index 0000000..4443073
--- /dev/null
+++ b/src/Lucene.Net.Benchmark/Support/TagSoup/tssl/tssl.rnc
@@ -0,0 +1,75 @@
+# This file is part of TagSoup and is Copyright 2002-2008 by John Cowan.
+#
+# TagSoup is licensed under the Apache License,
+# Version 2.0.  You may obtain a copy of this license at
+# http://www.apache.org/licenses/LICENSE-2.0 .  You may also have
+# additional legal rights not granted by this license.
+#
+# TagSoup is distributed in the hope that it will be useful, but
+# unless required by applicable law or agreed to in writing, TagSoup
+# is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS
+# OF ANY KIND, either express or implied; not even the implied warranty
+# of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+
+default namespace = "http://www.ccil.org/~cowan/XML/tagsoup/tssl"
+
+start = schema
+
+## A TSSL schema has a namespace, which is applied to the elements by default,
+## and a name, which is used solely for documentation.  It contains entity
+## definitions, a root element, and attributes to be applied to all elements.
+schema = element schema {
+		attribute ns {xsd:anyURI},
+		attribute prefix {xsd:NCName},
+		attribute name {xsd:NCName},
+		attribute version {"1.0"},
+		entity*,
+		group+,
+		\element,
+		\attribute*
+		}
+
+## An entity has a name and a Unicode codepoint in hex.
+entity = element entity {
+		attribute name {xsd:NCName},
+		attribute codepoint {xsd:string}
+		}
+
+## A group is a named group of elements.  Every element belongs to one
+## or more groups and has a content model consisting of one or more groups.
+group = element group {
+	attribute id {xsd:ID}
+	}
+
+## An element has a name and a namespace (currently ignored).
+## It can have any of several types of content and can be restartable
+## or not.  The element is also a member of one or more model groups
+## (with arbitrary names), and can contain as children zero or more
+## model groups.  Elements also have attributes and "natural" children.
+\element = element element {
+		attribute ns {xsd:anyURI}?,
+		attribute name {xsd:NCName},
+		attribute type {type},
+		attribute closeMode { "unclosable" | "restartable" }?,
+		attribute text-parent { "true" | "false" }?,
+		(element memberOf { attribute group {xsd:IDREF}}+ |
+		 element isRoot { empty} |
+		 element memberOfAny { empty }),
+		element contains { attribute group {xsd:IDREF}}*,
+		\attribute*,
+		\element*
+		}
+
+## Here are the attribute types:
+
+type = "element" | "any" | "empty" | "mixed" | "string" | "cdata"
+
+## An attribute has a name and a namespace (currently not supported).
+## It also has an optional type and an optional default value.
+\attribute = element attribute {
+	attribute ns {xsd:anyURI}?,
+	attribute name {xsd:NCName},
+	attribute type {"ID" | "IDREF" | "IDREFS" | "NMTOKEN" | "BOOLEAN"}?,
+	attribute default {xsd:string}?
+	}
+

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/198e5868/src/Lucene.Net.Benchmark/Support/TagSoup/tssl/tssl.xslt
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Benchmark/Support/TagSoup/tssl/tssl.xslt b/src/Lucene.Net.Benchmark/Support/TagSoup/tssl/tssl.xslt
new file mode 100644
index 0000000..22233d8
--- /dev/null
+++ b/src/Lucene.Net.Benchmark/Support/TagSoup/tssl/tssl.xslt
@@ -0,0 +1,220 @@
+<!-- Generate Java code to be inserted into HTMLSchema.java.  -->
+
+<!--
+// This file is part of TagSoup and is Copyright 2002-2008 by John Cowan.
+//
+// TagSoup is licensed under the Apache License,
+// Version 2.0.  You may obtain a copy of this license at
+// http://www.apache.org/licenses/LICENSE-2.0 .  You may also have
+// additional legal rights not granted by this license.
+//
+// TagSoup is distributed in the hope that it will be useful, but
+// unless required by applicable law or agreed to in writing, TagSoup
+// is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS
+// OF ANY KIND, either express or implied; not even the implied warranty
+// of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+-->
+
+<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+	xmlns:tssl="http://www.ccil.org/~cowan/XML/tagsoup/tssl"
+	version="1.0">
+
+  <xsl:output method="text"/>
+
+  <xsl:strip-space elements="*"/>
+
+  <!-- The main template.  This generates calls on the Schema routines
+       setURI(), setPrefix(), elementType(), parent(), attribute(),
+       and entity() in that order.  Several special cases are
+       handled by template calls.  -->
+  <xsl:template match="tssl:schema">
+    <!-- setURI() -->
+    <xsl:text>&#x9;&#x9;Uri = "</xsl:text>
+    <xsl:value-of select="@ns"/>
+    <xsl:text>";&#xA;</xsl:text>
+    <!-- setPrefix() -->
+    <xsl:text>&#x9;&#x9;Prefix = "</xsl:text>
+    <xsl:value-of select="@prefix"/>
+    <xsl:text>";&#xA;</xsl:text>
+    <!-- elementType() special cases -->
+    <xsl:text>&#x9;&#x9;ElementType("&lt;pcdata>", M_EMPTY, M_PCDATA, 0);&#xA;</xsl:text>
+    <xsl:text>&#x9;&#x9;ElementType("&lt;root>", </xsl:text>
+    <xsl:apply-templates select="tssl:element/tssl:isRoot"/>
+    <xsl:text>, M_EMPTY, 0);&#xA;</xsl:text>
+    <!-- elementType() main loop -->
+    <xsl:apply-templates select="//tssl:element">
+      <xsl:sort select="@name"/>
+    </xsl:apply-templates>
+    <!-- parent() special cases -->
+    <xsl:call-template name="parent">
+      <xsl:with-param name="elem" select="'&lt;pcdata>'"/>
+      <xsl:with-param name="parent" select="//tssl:element[@text-parent='true']/@name"/>
+    </xsl:call-template>
+    <xsl:call-template name="parent">
+      <xsl:with-param name="elem" select="tssl:element/@name"/>
+      <xsl:with-param name="parent" select="'&lt;root>'"/>
+    </xsl:call-template>
+    <!-- parent() main loop -->
+    <xsl:apply-templates select="//tssl:element/tssl:element" mode="parent">
+      <xsl:sort select="@name"/>
+    </xsl:apply-templates>
+    <xsl:apply-templates select="//tssl:element/tssl:attribute">
+      <xsl:sort select="../@name"/>
+      <xsl:sort select="@name"/>
+    </xsl:apply-templates>
+    <!-- attribute() main loop -->
+    <xsl:apply-templates select="tssl:attribute">
+      <xsl:sort select="@name"/>
+    </xsl:apply-templates>
+    <!-- entity() main loop -->
+    <xsl:apply-templates select="tssl:entity">
+      <xsl:sort select="@name"/>
+    </xsl:apply-templates>
+  </xsl:template>
+
+  <!-- Generates a single call to elementType().  -->
+  <xsl:template match="tssl:element">
+    <xsl:text>&#x9;&#x9;ElementType("</xsl:text>
+    <xsl:value-of select="@name"/>
+    <xsl:text>", </xsl:text>
+    <xsl:choose>
+      <xsl:when test="@type = 'element'">
+        <xsl:apply-templates select="tssl:contains"/>
+      </xsl:when>
+      <xsl:when test="@type = 'string'">
+        <xsl:text>M_PCDATA</xsl:text>
+      </xsl:when>
+      <xsl:when test="@type = 'mixed'">
+        <xsl:text>M_PCDATA|</xsl:text>
+        <xsl:apply-templates select="tssl:contains"/>
+      </xsl:when>
+      <xsl:when test="@type = 'empty'">
+        <xsl:text>M_EMPTY</xsl:text>
+      </xsl:when>
+      <xsl:when test="@type = 'any'">
+        <xsl:text>M_ANY</xsl:text>
+      </xsl:when>
+      <xsl:when test="@type = 'cdata'">
+        <xsl:text>M_PCDATA</xsl:text>
+      </xsl:when>
+    </xsl:choose>
+    <xsl:text>, </xsl:text>
+    <xsl:apply-templates select="tssl:memberOf"/>
+    <xsl:apply-templates select="tssl:memberOfAny"/>
+    <xsl:apply-templates select="tssl:isRoot"/>
+    <xsl:text>, </xsl:text>
+    <xsl:choose>
+      <xsl:when test="@type = 'cdata'">
+        <xsl:text>F_CDATA</xsl:text>
+      </xsl:when>
+      <xsl:when test="@closeMode = 'restartable'">
+        <xsl:text>F_RESTART</xsl:text>
+      </xsl:when>
+      <xsl:when test="@closeMode = 'unclosable'">
+        <xsl:text>F_NOFORCE</xsl:text>
+      </xsl:when>
+      <xsl:otherwise>
+        <xsl:text>0</xsl:text>
+      </xsl:otherwise>
+    </xsl:choose>
+    <xsl:text>);&#xA;</xsl:text>
+  </xsl:template>
+
+  <!-- Applied from tssl:element to generate the contains argument.  -->
+  <xsl:template match="tssl:contains">
+    <xsl:value-of select="@group"/>
+    <xsl:if test="position() != last()">
+      <xsl:text>|</xsl:text>
+    </xsl:if>
+  </xsl:template>
+
+  <!-- Applied from tssl:element to generate the memberOf argument.  -->
+  <xsl:template match="tssl:memberOf">
+    <xsl:value-of select="@group"/>
+    <xsl:if test="position() != last()">
+      <xsl:text>|</xsl:text>
+    </xsl:if>
+  </xsl:template>
+
+  <!-- Applied from tssl:element to handle memberOfAny.  -->
+  <xsl:template match="tssl:memberOfAny">
+    <xsl:text>(int)(M_ANY &amp; ~M_ROOT)</xsl:text>
+  </xsl:template>
+
+  <!-- Applied from tssl:element to handle isRoot.  -->
+  <xsl:template match="tssl:isRoot">
+    <xsl:text>M_ROOT</xsl:text>
+  </xsl:template>
+
+  <!-- Generates a single call to parent().  The mode is used to prevent XSLT
+       from getting confused and generating elementType calls instead.  -->
+  <xsl:template match="tssl:element/tssl:element" name="parent" mode="parent">
+    <xsl:param name="elem" select="@name"/>
+    <xsl:param name="parent" select="../@name"/>
+    <xsl:text>&#x9;&#x9;Parent("</xsl:text>
+    <xsl:value-of select="$elem"/>
+    <xsl:text>", "</xsl:text>
+    <xsl:value-of select="$parent"/>
+    <xsl:text>");&#xA;</xsl:text>
+  </xsl:template>
+
+  <!-- Generates a single call to attribute().  -->
+  <xsl:template match="tssl:element/tssl:attribute" name="tssl:attribute">
+    <xsl:param name="elem" select="../@name"/>
+    <xsl:param name="attr" select="@name"/>
+    <xsl:param name="type" select="@type"/>
+    <xsl:param name="default" select="@default"/>
+    <xsl:text>&#x9;&#x9;Attribute("</xsl:text>
+    <xsl:value-of select="$elem"/>
+    <xsl:text>", "</xsl:text>
+    <xsl:value-of select="$attr"/>
+    <xsl:text>", "</xsl:text>
+    <xsl:choose>
+      <xsl:when test="$type">
+        <xsl:value-of select="$type"/>
+      </xsl:when>
+      <xsl:when test="not($type)">
+        <xsl:text>CDATA</xsl:text>
+      </xsl:when>
+    </xsl:choose>
+    <xsl:text>", </xsl:text>
+    <xsl:choose>
+      <xsl:when test="$default">
+        <xsl:text>"</xsl:text>
+        <xsl:value-of select="$default"/>
+        <xsl:text>"</xsl:text>
+      </xsl:when>
+      <xsl:when test="not($default)">
+        <xsl:text>null</xsl:text>
+      </xsl:when>
+    </xsl:choose>
+    <xsl:text>);&#xA;</xsl:text>
+  </xsl:template>
+
+  <!-- Generates calls to attribute() (using the above template)
+       based on the global attribute definitions.  -->
+  <xsl:template match="tssl:schema/tssl:attribute">
+    <xsl:variable name="attr" select="@name"/>
+    <xsl:variable name="type" select="@type"/>
+    <xsl:variable name="default" select="@default"/>
+    <xsl:for-each select="//tssl:element">
+      <xsl:sort select="@name"/>
+      <xsl:call-template name="tssl:attribute">
+        <xsl:with-param name="elem" select="@name"/>
+        <xsl:with-param name="attr" select="$attr"/>
+        <xsl:with-param name="type" select="$type"/>
+        <xsl:with-param name="default" select="$default"/>
+      </xsl:call-template>
+    </xsl:for-each>
+  </xsl:template>
+
+  <!-- Generates a single call to entity().  -->
+  <xsl:template match="tssl:entity">
+    <xsl:text>&#x9;&#x9;Entity("</xsl:text>
+    <xsl:value-of select="@name"/>
+    <xsl:text>", 0x</xsl:text>
+    <xsl:value-of select="@codepoint"/>
+    <xsl:text>);&#xA;</xsl:text>
+  </xsl:template>
+
+</xsl:transform>