]> granicus.if.org Git - docbook-dsssl/commitdiff
Upgraded tools
authorNorman Walsh <ndw@nwalsh.com>
Tue, 18 Jan 2005 18:04:03 +0000 (18:04 +0000)
committerNorman Walsh <ndw@nwalsh.com>
Tue, 18 Jan 2005 18:04:03 +0000 (18:04 +0000)
docbook/relaxng/tools/db4-upgrade.xsl
docbook/relaxng/tools/doc2dtd.xsl
docbook/relaxng/tools/html.xsl
docbook/relaxng/tools/rngdocxml.xsl

index 8fa799b5b7a9a02af541dc2be776ef799b5f0681..2404b27d7669749fc03390548649d95280f2b763 100644 (file)
   <!-- nop -->
 </xsl:template>
 
-<!--
-<xsl:template match="dedication/title|dedication/titleabbrev|dedication/subtitle
-                     |preface/title|preface/titleabbrev|preface/subtitle
-                     |chapter/title|chapter/titleabbrev|chapter/subtitle
-                     |appendix/title|appendix/titleabbrev|appendix/subtitle
-                     |article/title|article/titleabbrev|article/subtitle
-                     |partintro/title|partintro/titleabbrev|partintro/subtitle
-                     |part/title|part/titleabbrev|part/subtitle
-                     |sect1/title|sect1/titleabbrev|sect1/subtitle
-                     |sect2/title|sect2/titleabbrev|sect2/subtitle
-                     |sect3/title|sect3/titleabbrev|sect3/subtitle
-                     |sect4/title|sect4/titleabbrev|sect4/subtitle
-                     |sect5/title|sect5/titleabbrev|sect5/subtitle
-                     |section/title|section/titleabbrev|section/subtitle
-                     |formalpara/title|figure/title|example/title|equation/title
-                     |table/title|blockquote/title
-                     |caution/title|important/title|note/title|warning/title|tip/title
-                     |bibliodiv/title|glossarydiv/title|indexdiv/title
-                     |book/title
-                     |articleinfo/title
-                     "
-              priority="300">
-</xsl:template>
--->
+<xsl:template match="indexterm">
+  <!-- don't copy the defaulted significance='normal' attribute -->
+  <xsl:copy>
+    <xsl:for-each select="@*">
+      <xsl:if test="name(.) != 'significance'
+                   or string(.) != 'normal'">
+       <xsl:copy/>
+      </xsl:if>
+    </xsl:for-each>
+    <xsl:apply-templates/>
+  </xsl:copy>
+</xsl:template>
 
 <!-- ====================================================================== -->
 
index 77c92de4c82b36672c765833e30430b9813f4d50..9b86f947070a1305534cf4c9c4202e9a8ee9f78c 100644 (file)
                xmlns:rng="http://relaxng.org/ns/structure/1.0"
                xmlns:doc="http://nwalsh.com/xmlns/schema-doc/"
                xmlns:ctrl="http://nwalsh.com/xmlns/schema-control/"
+               xmlns:dtd="http://nwalsh.com/xmlns/dtd/"
+               exclude-result-prefixes="exsl rng doc ctrl"
                version="1.0">
 
 <!-- attempts, and currently fails, to produce a DTD -->
 
-<xsl:output method="text"/>
-<xsl:strip-space elements="*"/>
+<xsl:include href="doc2dtd-tables.xsl"/>
+
+<xsl:key name="pattern" match="rng:define" use="@name"/>
 
-<xsl:variable name="start" select="/rng:grammar/rng:start"/>
+<xsl:output method="xml" indent="yes"/>
+<xsl:strip-space elements="*"/>
 
 <xsl:template match="/">
   <xsl:variable name="trimmed">
     <xsl:apply-templates mode="trim"/>
   </xsl:variable>
 
-  <xsl:variable name="cleaned">
-    <xsl:apply-templates select="exsl:node-set($trimmed)/*" mode="cleanup"/>
-  </xsl:variable>
+  <dtd:dtd>
+    <xsl:apply-templates select="exsl:node-set($trimmed)/*"/>
+  </dtd:dtd>
+</xsl:template>
 
-  <xsl:apply-templates select="exsl:node-set($cleaned)/*"/>
+<xsl:template match="rng:element">
+  <xsl:choose>
+    <xsl:when test="../@name = 'db.titlereq.info'"/>
+    <xsl:when test="../@name = 'db.titleonly.info'"/>
+    <xsl:when test="../@name = 'db.titleonlyreq.info'"/>
+    <xsl:when test="../@name = 'db.titleforbidden.info'"/>
+    <xsl:when test="starts-with(../@name, 'db._')"/>
+    <xsl:otherwise>
+      <xsl:comment>
+       <xsl:value-of select="../@name"/>
+      </xsl:comment>
+      <dtd:element name="{@name}">
+       <xsl:apply-templates select="doc:content-model" mode="content-model"/>
+      </dtd:element>
+
+      <dtd:attlist name="{@name}">
+       <xsl:apply-templates select="doc:attributes" mode="attributes"/>
+      </dtd:attlist>
+    </xsl:otherwise>
+  </xsl:choose>
 </xsl:template>
 
-<xsl:key name="defs" match="rng:define" use="@name"/>
+<xsl:template match="rng:define">
+  <xsl:choose>
+    <xsl:when test="@name = 'db.common.attributes'
+                   or @name = 'db.common.linking.attributes'">
+      <dtd:pe name="{@name}">
+       <xsl:apply-templates select=".//rng:attribute" mode="attributes">
+         <xsl:with-param name="override" select="1"/>
+       </xsl:apply-templates>
+      </dtd:pe>
+    </xsl:when>
+
+    <!-- Handle the indexterm patterns -->
 
-<xsl:template match="rng:div">
-  <xsl:apply-templates select="rng:define"/>
-</xsl:template>
+    <xsl:when test="@name = 'db.indexterm.startofrange'
+                   or @name = 'db.indexterm.endofrange'">
+      <!-- db.indexterm.singular handles all three cases -->
+    </xsl:when>
 
-<xsl:template match="ctrl:alternate-define"/>
+    <!-- Handle the row patterns -->
 
-<xsl:template match="rng:define[@name='db.info.titlereq']"/>
-<xsl:template match="rng:define[@name='db.info.titleonly']"/>
-<xsl:template match="rng:define[@name='db.info.titleonlyreq']"/>
-<xsl:template match="rng:define[@name='db.info.titleforbidden']"/>
+    <xsl:when test="@name = 'db.entrytbl.row' and key('pattern', 'db.row')">
+      <!-- db.row handles both cases -->
+    </xsl:when>
 
-<xsl:template match="rng:define">
-  <xsl:apply-templates select="rng:element"/>
-</xsl:template>
+    <!-- Handle the thead patterns -->
 
-<xsl:template match="rng:element">
-  <xsl:if test="@name">
-    <xsl:variable name="name" select="@name"/>
-    <xsl:variable name="defname" select="ancestor::rng:define/@name"/>
-
-    <!--
-    <xsl:message>
-      <xsl:value-of select="@name"/>
-      <xsl:text> (</xsl:text>
-      <xsl:value-of select="../@name"/>
-      <xsl:text>)</xsl:text>
-    </xsl:message>
-    -->
-    <xsl:text>&lt;!ELEMENT </xsl:text>
-    <xsl:value-of select="@name"/>
-    <xsl:text> </xsl:text>
-    <xsl:apply-templates select="doc:content-model" mode="model"/>
-    <xsl:text>&gt;&#10;&#10;</xsl:text>
-
-    <xsl:text>&lt;!ATTLIST </xsl:text>
-    <xsl:value-of select="@name"/>
-    <xsl:text>&#10;</xsl:text>
-
-    <xsl:if test="$start//rng:ref[@name = $defname]">
-      <xsl:text>&#9;xmlns&#9;CDATA #FIXED "http://docbook.org/docbook-ng"&#10;</xsl:text>
-      <xsl:text>&#9;version&#9;CDATA&#9;#IMPLIED&#10;</xsl:text>
-    </xsl:if>
+    <xsl:when test="@name = 'db.cals.thead' and key('pattern', 'db.html.thead')">
+      <xsl:variable name="html.thead"
+                   select="key('pattern', 'db.html.thead')"/>
 
-    <xsl:apply-templates select="doc:attributes" mode="attlist"/>
-    <xsl:text>&gt;&#10;&#10;</xsl:text>
-  </xsl:if>
-</xsl:template>
+      <xsl:copy-of select="$merged-thead"/>
+
+      <dtd:attlist name="thead">
+       <xsl:apply-templates select="rng:element/doc:attributes"
+                            mode="attributes"/>
+       <xsl:apply-templates select="$html.thead/rng:element/doc:attributes"
+                            mode="attributes"/>
+      </dtd:attlist>
+    </xsl:when>
 
-<!-- ====================================================================== -->
-<!-- doc:content-model -->
+    <xsl:when test="@name = 'db.cals.entrytbl.thead'">
+      <!-- nop; handled by the db.cals.thead branch -->
+    </xsl:when>
 
-<xsl:template match="doc:content-model" mode="model">
-  <xsl:choose>
-    <xsl:when test="rng:choice|rng:oneOrMore|rng:zeroOrMore|rng:interleave|rng:group">
-      <xsl:apply-templates mode="model"/>
+    <xsl:when test="@name = 'db.html.thead' and key('pattern', 'db.cals.thead')">
+      <!-- nop; handled by the db.cals.thead branch -->
+    </xsl:when>
+
+    <!-- Handle the tfoot patterns -->
+
+    <xsl:when test="@name = 'db.cals.tfoot' and key('pattern', 'db.html.tfoot')">
+      <xsl:variable name="html.tfoot"
+                   select="key('pattern', 'db.html.tfoot')"/>
+
+      <xsl:copy-of select="$merged-tfoot"/>
+
+      <dtd:attlist name="tfoot">
+       <xsl:apply-templates select="rng:element/doc:attributes"
+                            mode="attributes"/>
+       <xsl:apply-templates select="$html.tfoot/rng:element/doc:attributes"
+                            mode="attributes"/>
+      </dtd:attlist>
+    </xsl:when>
+
+    <xsl:when test="@name = 'db.html.tfoot' and key('pattern', 'db.cals.tfoot')">
+      <!-- nop; handled by the db.cals.tfoot branch -->
+    </xsl:when>
+
+    <!-- Handle the tbody patterns -->
+
+    <xsl:when test="@name = 'db.cals.tbody' and key('pattern', 'db.html.tbody')">
+      <xsl:variable name="html.tbody"
+                   select="key('pattern', 'db.html.tbody')"/>
+
+      <xsl:copy-of select="$merged-tbody"/>
+
+      <dtd:attlist name="tbody">
+       <xsl:apply-templates select="rng:element/doc:attributes"
+                            mode="attributes"/>
+       <xsl:apply-templates select="$html.tbody/rng:element/doc:attributes"
+                            mode="attributes"/>
+      </dtd:attlist>
+    </xsl:when>
+
+    <xsl:when test="@name = 'db.cals.entrytbl.tbody'">
+      <!-- nop; handled by the db.cals.thead branch -->
+    </xsl:when>
+
+    <xsl:when test="@name = 'db.html.tbody' and key('pattern', 'db.cals.tbody')">
+      <!-- nop; handled by the db.cals.tbody branch -->
+    </xsl:when>
+
+    <!-- Handle the informaltable patterns -->
+
+    <xsl:when test="@name = 'db.cals.informaltable'
+                   and key('pattern', 'db.html.informaltable')">
+      <xsl:variable name="html.informaltable"
+                   select="key('pattern', 'db.html.informaltable')"/>
+
+      <xsl:copy-of select="$merged-informaltable"/>
+
+      <dtd:attlist name="informaltable">
+       <xsl:apply-templates select="rng:element/doc:attributes"
+                            mode="attributes"/>
+       <xsl:apply-templates select="$html.informaltable/rng:element/doc:attributes"
+                            mode="attributes"/>
+      </dtd:attlist>
+    </xsl:when>
+
+    <xsl:when test="@name = 'db.html.informaltable'
+                   and key('pattern', 'db.cals.informaltable')">
+      <!-- nop; handled by the db.cals.informaltable branch -->
+    </xsl:when>
+
+    <!-- Handle the table patterns -->
+
+    <xsl:when test="@name = 'db.cals.table'
+                   and key('pattern', 'db.html.table')">
+      <xsl:variable name="html.table"
+                   select="key('pattern', 'db.html.table')"/>
+
+      <xsl:copy-of select="$merged-table"/>
+
+      <dtd:attlist name="table">
+       <xsl:apply-templates select="rng:element/doc:attributes"
+                            mode="attributes"/>
+       <xsl:apply-templates select="$html.table/rng:element/doc:attributes"
+                            mode="attributes"/>
+      </dtd:attlist>
     </xsl:when>
+
+    <xsl:when test="@name = 'db.html.table'
+                   and key('pattern', 'db.cals.table')">
+      <!-- nop; handled by the db.cals.table branch -->
+    </xsl:when>
+
     <xsl:otherwise>
-      <xsl:text>(</xsl:text>
-      <xsl:apply-templates mode="model"/>
-      <xsl:text>)</xsl:text>
+      <xsl:apply-templates/>
     </xsl:otherwise>
   </xsl:choose>
 </xsl:template>
 
-<xsl:template match="rng:group" mode="model">
-  <xsl:text>(</xsl:text>
-  <xsl:for-each select="*">
-    <xsl:apply-templates select="." mode="model"/>
-    <xsl:if test="position() != last()">, </xsl:if>
-  </xsl:for-each>
-  <xsl:text>)</xsl:text>
+<xsl:template match="*">
+  <xsl:apply-templates/>
 </xsl:template>
 
-<xsl:template match="rng:choice" mode="model">
-  <xsl:text>(</xsl:text>
-  <xsl:for-each select="*">
-    <xsl:apply-templates select="." mode="model"/>
-    <xsl:if test="position() != last()"> | </xsl:if>
-  </xsl:for-each>
-  <xsl:text>)</xsl:text>
+<xsl:template match="comment()|text()|processing-instruction()">
+  <!-- nop -->
 </xsl:template>
 
-<xsl:template match="rng:interleave" mode="model">
-  <xsl:text>(</xsl:text>
-  <xsl:for-each select="*">
-    <xsl:apply-templates select="." mode="model"/>
-    <xsl:if test="position() != last()">, </xsl:if>
-  </xsl:for-each>
-  <xsl:text>)</xsl:text>
-</xsl:template>
+<!-- ============================================================ -->
 
-<xsl:template match="rng:zeroOrMore" mode="model">
-  <xsl:text>(</xsl:text>
-  <xsl:for-each select="*">
-    <xsl:apply-templates select="." mode="model"/>
-    <xsl:if test="position() != last()"> | </xsl:if>
-  </xsl:for-each>
-  <xsl:text>)*</xsl:text>
+<xsl:template match="doc:content-model" mode="content-model">
+  <xsl:choose>
+    <xsl:when test=".//rng:group|.//rng:choice|.//rng:interleave">
+      <xsl:apply-templates mode="content-model"/>
+    </xsl:when>
+    <xsl:otherwise>
+      <dtd:group>
+       <xsl:apply-templates mode="content-model"/>
+      </dtd:group>
+    </xsl:otherwise>
+  </xsl:choose>
 </xsl:template>
 
-<xsl:template match="rng:oneOrMore" mode="model">
-  <xsl:text>(</xsl:text>
-  <xsl:for-each select="*">
-    <xsl:apply-templates select="." mode="model"/>
-    <xsl:if test="position() != last()"> | </xsl:if>
-  </xsl:for-each>
-  <xsl:text>)+</xsl:text>
+<xsl:template match="rng:group" mode="content-model">
+  <xsl:param name="repeat" select="''"/>
+  <dtd:group>
+    <xsl:if test="$repeat != ''">
+      <xsl:attribute name="repeat">
+       <xsl:value-of select="$repeat"/>
+      </xsl:attribute>
+    </xsl:if>
+    <xsl:apply-templates select="*" mode="content-model"/>
+  </dtd:group>
 </xsl:template>
 
-<xsl:template match="rng:optional" mode="model">
-  <xsl:apply-templates mode="model"/>
-  <xsl:text>?</xsl:text>
+<xsl:template match="rng:choice" mode="content-model">
+  <xsl:param name="repeat" select="''"/>
+  <dtd:choice>
+    <xsl:if test="$repeat != ''">
+      <xsl:attribute name="repeat">
+       <xsl:value-of select="$repeat"/>
+      </xsl:attribute>
+    </xsl:if>
+    <xsl:apply-templates select="*" mode="content-model"/>
+  </dtd:choice>
 </xsl:template>
 
-<xsl:template match="rng:ref" mode="model">
-  <xsl:variable name="def" select="key('defs', @name)"/>
-  <xsl:value-of select="$def/rng:element/@name"/>
+<xsl:template match="rng:interleave" mode="content-model">
+  <xsl:param name="repeat" select="''"/>
+  <dtd:choice repeat="*">
+    <xsl:apply-templates select="*" mode="content-model"/>
+  </dtd:choice>
 </xsl:template>
 
-<xsl:template match="rng:text" mode="model">
-  <xsl:text>#PCDATA</xsl:text>
+<xsl:template match="rng:optional" mode="content-model">
+  <xsl:param name="repeat" select="''"/>
+  <xsl:apply-templates mode="content-model">
+    <xsl:with-param name="repeat" select="'?'"/>
+  </xsl:apply-templates>
 </xsl:template>
 
-<xsl:template match="rng:empty" mode="model">
-  <xsl:text>EMPTY</xsl:text>
+<xsl:template match="rng:zeroOrMore" mode="content-model">
+  <xsl:param name="repeat" select="''"/>
+  <dtd:choice repeat="*">
+    <xsl:apply-templates select="*" mode="content-model"/>
+  </dtd:choice>
 </xsl:template>
 
-<xsl:template match="rng:data" mode="model">
-  <xsl:message>Using #PCDATA instead of <xsl:value-of select="@type"/></xsl:message>
-  <xsl:text>#PCDATA</xsl:text>
+<xsl:template match="rng:oneOrMore" mode="content-model">
+  <xsl:param name="repeat" select="''"/>
+  <dtd:choice repeat="+">
+    <xsl:apply-templates select="*" mode="content-model"/>
+  </dtd:choice>
 </xsl:template>
 
-<!-- ====================================================================== -->
-<!-- doc:attributes -->
-
-<xsl:template match="doc:attributes" mode="attlist">
-  <xsl:apply-templates mode="attlist"/>
+<xsl:template match="rng:text" mode="content-model">
+  <xsl:param name="repeat" select="''"/>
+  <dtd:PCDATA/>
 </xsl:template>
 
-<xsl:template match="rng:attribute" mode="attlist">
-  <xsl:text>&#9;</xsl:text>
-  <xsl:value-of select="@name"/>
-
-  <xsl:text>&#9;</xsl:text>
-  <xsl:if test="string-length(@name) &lt; 8">
-    <xsl:text>&#9;</xsl:text>
-  </xsl:if>
+<xsl:template match="rng:empty" mode="content-model">
+  <xsl:param name="repeat" select="''"/>
+  <dtd:EMPTY/>
+</xsl:template>
 
+<xsl:template match="rng:ref" mode="content-model">
+  <xsl:param name="repeat" select="''"/>
+  <xsl:variable name="def" select="key('pattern', @name)"/>
   <xsl:choose>
-    <xsl:when test="rng:data">
-      <xsl:choose>
-       <xsl:when test="rng:data/@type = 'integer'">CDATA</xsl:when>
-       <xsl:otherwise><xsl:value-of select="rng:data/@type"/></xsl:otherwise>
-      </xsl:choose>
+    <xsl:when test="@name = 'db.indexterm.startofrange'
+                   and (../rng:ref[@name='db.indexterm.singular']
+                        or ../rng:ref[@name='db.indexterm.endofrange'])">
+      <!-- suppress -->
     </xsl:when>
-    <xsl:when test="rng:choice">
-      <xsl:text>(</xsl:text>
-      <xsl:for-each select="rng:choice/rng:value">
-       <xsl:value-of select="."/>
-       <xsl:if test="position() != last()">|</xsl:if>
-      </xsl:for-each>
-      <xsl:text>)</xsl:text>
+    <xsl:when test="@name = 'db.indexterm.endofrange'
+                   and ../rng:ref[@name='db.indexterm.singular']">
+      <!-- suppress -->
     </xsl:when>
-    <xsl:otherwise>CDATA</xsl:otherwise>
-  </xsl:choose>
-
-  <xsl:text>&#9;</xsl:text>
-  <xsl:choose>
-    <xsl:when test="ancestor::rng:optional">
-      <xsl:text>#IMPLIED</xsl:text>
+    <xsl:when test="@name = 'db.html.table'
+                   and ../rng:ref[@name='db.cals.table']">
+      <!-- suppress -->
+    </xsl:when>
+    <xsl:when test="@name = 'db.html.informaltable'
+                   and ../rng:ref[@name='db.cals.informaltable']">
+      <!-- suppress -->
+    </xsl:when>
+    <xsl:when test="$def/rng:element">
+      <xsl:if test="$def/rng:element/@name != ''">
+       <dtd:ref name="{$def/rng:element/@name}">
+         <xsl:if test="$repeat != ''">
+           <xsl:attribute name="repeat">
+             <xsl:value-of select="$repeat"/>
+           </xsl:attribute>
+         </xsl:if>
+       </dtd:ref>
+      </xsl:if>
     </xsl:when>
     <xsl:otherwise>
-      <xsl:text>#REQUIRED</xsl:text>
+      <dtd:peref name="{@name}"/>
     </xsl:otherwise>
   </xsl:choose>
+</xsl:template>
+
+<!-- ============================================================ -->
 
-  <xsl:text>&#10;</xsl:text>
+<xsl:template match="doc:attributes" mode="attributes">
+  <xsl:apply-templates select=".//rng:attribute" mode="attributes"/>
 </xsl:template>
 
-<xsl:template match="rng:interleave|rng:optional" mode="attlist">
-  <xsl:apply-templates mode="attlist"/>
+<xsl:template match="rng:attribute" mode="attributes">
+  <xsl:param name="override" select="0"/>
+
+  <xsl:choose>
+    <xsl:when test="$override = 0">
+      <xsl:choose>
+       <xsl:when test="@name = 'xml:id'">
+         <dtd:peref name="db.common.attributes"/>
+       </xsl:when>
+       <xsl:when test="@name = 'version'"/>
+       <xsl:when test="@name = 'xml:lang'"/>
+       <xsl:when test="@name = 'xml:base'"/>
+       <xsl:when test="@name = 'remap'"/>
+       <xsl:when test="@name = 'xreflabel'"/>
+       <xsl:when test="@name = 'revisionflag'"/>
+       <xsl:when test="@name = 'arch'"/>
+       <xsl:when test="@name = 'condition'"/>
+       <xsl:when test="@name = 'conformance'"/>
+       <xsl:when test="@name = 'os'"/>
+       <xsl:when test="@name = 'revision'"/>
+       <xsl:when test="@name = 'security'"/>
+       <xsl:when test="@name = 'userlevel'"/>
+       <xsl:when test="@name = 'vendor'"/>
+       <xsl:when test="@name = 'wordsize'"/>
+
+       <xsl:when test="@name = 'linkend'">
+         <dtd:peref name="db.common.linking.attributes"/>
+       </xsl:when>
+       <xsl:when test="@name = 'xlink:href'"/>
+       <xsl:when test="@name = 'xlink:type'"/>
+       <xsl:when test="@name = 'xlink:role'"/>
+       <xsl:when test="@name = 'xlink:arcrole'"/>
+       <xsl:when test="@name = 'xlink:title'"/>
+       <xsl:when test="@name = 'xlink:show'"/>
+       <xsl:when test="@name = 'xlink:actuate'"/>
+
+       <xsl:otherwise>
+         <dtd:attribute name="{@name}">
+           <xsl:attribute name="occurs">
+             <xsl:choose>
+               <xsl:when test="ancestor::rng:optional">optional</xsl:when>
+               <xsl:when test="ancestor::rng:choice">optional</xsl:when>
+               <xsl:otherwise>required</xsl:otherwise>
+             </xsl:choose>
+           </xsl:attribute>
+           <xsl:if test="rng:data">
+             <xsl:attribute name="type">
+               <xsl:value-of select="rng:data/@type"/>
+             </xsl:attribute>
+           </xsl:if>
+           <xsl:if test=".//rng:value">
+             <xsl:text>(</xsl:text>
+             <xsl:for-each select=".//rng:value">
+               <xsl:if test="position() &gt; 1">|</xsl:if>
+               <xsl:value-of select="."/>
+             </xsl:for-each>
+
+             <!-- HACK -->
+             <xsl:if test="@name = 'class' and .//rng:value[1] = 'singular'">
+               <xsl:text>|startofrange|endofrange</xsl:text>
+             </xsl:if>
+
+             <xsl:text>)</xsl:text>
+           </xsl:if>
+         </dtd:attribute>
+       </xsl:otherwise>
+      </xsl:choose>
+    </xsl:when>
+    <xsl:otherwise>
+      <dtd:attribute name="{@name}">
+       <xsl:attribute name="occurs">
+         <xsl:choose>
+           <xsl:when test="ancestor::rng:optional">optional</xsl:when>
+           <xsl:when test="ancestor::rng:choice">optional</xsl:when>
+           <xsl:otherwise>required</xsl:otherwise>
+         </xsl:choose>
+       </xsl:attribute>
+       <xsl:if test="rng:data">
+         <xsl:attribute name="type">
+           <xsl:value-of select="rng:data/@type"/>
+         </xsl:attribute>
+       </xsl:if>
+       <xsl:if test="rng:choice">
+         <xsl:text>(</xsl:text>
+         <xsl:for-each select="rng:choice/rng:value">
+           <xsl:if test="position() &gt; 1">|</xsl:if>
+           <xsl:value-of select="."/>
+         </xsl:for-each>
+         <xsl:text>)</xsl:text>
+       </xsl:if>
+      </dtd:attribute>
+    </xsl:otherwise>
+  </xsl:choose>
 </xsl:template>
 
-<!-- ====================================================================== -->
-<!-- trim -->
-
-<xsl:template match="rng:ref[@name='indexterm.startofrange']" mode="trim"/>
-<xsl:template match="rng:ref[@name='indexterm.endofrange']" mode="trim"/>
-<xsl:template match="rng:ref[@name='html.informaltable']" mode="trim"/>
-<xsl:template match="rng:ref[@name='html.table']" mode="trim"/>
-<xsl:template match="rng:ref[@name='any.svg']" mode="trim"/>
-<xsl:template match="rng:ref[@name='any.mml']" mode="trim"/>
-<xsl:template match="rng:data[preceding-sibling::rng:data]" mode="trim"/>
-
-<xsl:template match="rng:define[@name='indexterm.startofrange']" mode="trim"/>
-<xsl:template match="rng:define[@name='indexterm.endofrange']" mode="trim"/>
-<xsl:template match="rng:define[@name='html.informaltable']" mode="trim"/>
-<xsl:template match="rng:define[@name='html.table']" mode="trim"/>
-<xsl:template match="rng:define[@name='html.thead']" mode="trim"/>
-<xsl:template match="rng:define[@name='html.tbody']" mode="trim"/>
-<xsl:template match="rng:define[@name='html.tfoot']" mode="trim"/>
-<xsl:template match="rng:define[@name='any.svg']" mode="trim"/>
-<xsl:template match="rng:define[@name='any.mml']" mode="trim"/>
-<xsl:template match="rng:define[@name='text.phrase']" mode="trim"/>
+<!-- ============================================================ -->
 
-<xsl:template match="*" mode="trim">
+<xsl:template match="*[ancestor::doc:attributes]" mode="trim" priority="1000">
   <xsl:copy>
     <xsl:copy-of select="@*"/>
     <xsl:apply-templates mode="trim"/>
   </xsl:copy>
 </xsl:template>
 
-<xsl:template match="comment()|processing-instruction()|text()" mode="trim">
-  <xsl:copy/>
+<xsl:template match="rng:optional[parent::rng:interleave]" mode="trim"
+             priority="100">
+  <!-- optional in interleave is redundant for DTD syntax -->
+  <xsl:apply-templates mode="trim"/>
 </xsl:template>
 
-<!-- ====================================================================== -->
-<!-- cleanup -->
-
-<xsl:template match="doc:content-model[count(*) = 1 and rng:text]" mode="cleanup">
-  <doc:content-model>
-    <rng:zeroOrMore>
-      <rng:text/>
-    </rng:zeroOrMore>
-  </doc:content-model>
+<xsl:template match="rng:choice[rng:ref[@name='db.titlereq.info']
+        and rng:group[rng:optional[rng:ref[@name='db.titleforbidden.info']]]]"
+             mode="trim">
+<!--
+  Turn this: (((title|titleabbrev|subtitle)*,info?)|info)
+  into this:   (title|titleabbrev|subtitle)*,info?)
+-->
+  <xsl:apply-templates select="rng:group" mode="trim"/>
 </xsl:template>
 
-<xsl:template match="doc:content-model[.//rng:text]" mode="cleanup">
-  <xsl:variable name="children">
-    <xsl:copy-of select=".//rng:ref"/>
-  </xsl:variable>
+<xsl:template match="rng:choice[rng:optional[rng:ref[@name='db.info']]
+        and rng:group[rng:optional[rng:ref[@name='db.titleforbidden.info']]]]"
+             mode="trim">
+<!--
+  Turn this: (((title|titleabbrev|subtitle)*,info?)|info?)
+  into this:   (title|titleabbrev|subtitle)*,info?)
+-->
+  <xsl:apply-templates select="rng:group" mode="trim"/>
+</xsl:template>
 
-  <doc:content-model>
-    <rng:zeroOrMore>
-      <rng:text/>
-      <xsl:for-each select="exsl:node-set($children)/*">
-       <xsl:variable name="name" select="@name"/>
-       <xsl:if test="not(preceding-sibling::rng:ref[@name = $name])">
-         <xsl:copy-of select="."/>
-       </xsl:if>
-      </xsl:for-each>
-    </rng:zeroOrMore>
-  </doc:content-model>
+<xsl:template match="rng:define" mode="trim">
+  <!--xsl:message>Trimming <xsl:value-of select="@name"/></xsl:message-->
+  <xsl:copy>
+    <xsl:copy-of select="@*"/>
+    <xsl:apply-templates mode="trim"/>
+  </xsl:copy>
 </xsl:template>
 
-<xsl:template match="*" mode="cleanup">
+<xsl:template match="*" mode="trim">
   <xsl:copy>
     <xsl:copy-of select="@*"/>
-    <xsl:apply-templates mode="cleanup"/>
+    <xsl:apply-templates mode="trim"/>
   </xsl:copy>
 </xsl:template>
 
-<xsl:template match="comment()|processing-instruction()|text()" mode="cleanup">
+<xsl:template match="comment()|processing-instruction()|text()" mode="trim">
   <xsl:copy/>
 </xsl:template>
 
+<!-- ============================================================ -->
+
 </xsl:stylesheet>
index 58907407ee932c56bf4908a0d0f50b2edc6a3a2e..6ae7a31d551621f14850941d092f203a7b56771c 100644 (file)
@@ -27,6 +27,8 @@
   <xsl:key name="genid" match="rng:element" use="generate-id()"/>
 
   <xsl:template match="/">
+    <xsl:variable name="source" select="/"/>
+
     <xsl:variable name="allElemNS">
       <xsl:apply-templates select="//rng:element[@name and generate-id(.)
                                     =generate-id(key('elements',@name)[1])]"
@@ -50,7 +52,8 @@
       <xsl:variable name="prev" select="preceding-sibling::*[1]/@filename"/>
       <xsl:variable name="next" select="following-sibling::*[1]/@filename"/>
 
-      <xsl:apply-templates select="key('genid', @id)" mode="chunk">
+      <xsl:apply-templates select="$source" mode="chunk">
+       <xsl:with-param name="id" select="@id"/>
        <xsl:with-param name="home" select="$home"/>
        <xsl:with-param name="prev" select="$prev"/>
        <xsl:with-param name="next" select="$next"/>
   </xsl:template>
 
   <xsl:template match="rng:element" mode="names">
+<!--
+    <xsl:message>
+      <xsl:text>element: </xsl:text>
+      <xsl:value-of select="ancestor::rng:define[1]/@name"/>
+    </xsl:message>
+-->
+
     <element id="{generate-id()}" define="{ancestor::rng:define[1]/@name}">
       <xsl:attribute name="filename">
        <xsl:apply-templates select="." mode="filename"/>
     <xsl:value-of select="'.html'"/>
   </xsl:template>
 
+  <xsl:template match="/" mode="chunk">
+    <xsl:param name="id"/>
+    <xsl:param name="home"/>
+    <xsl:param name="prev"/>
+    <xsl:param name="next"/>
+
+    <xsl:apply-templates select="key('genid', $id)" mode="chunk">
+      <xsl:with-param name="home" select="$home"/>
+      <xsl:with-param name="prev" select="$prev"/>
+      <xsl:with-param name="next" select="$next"/>
+    </xsl:apply-templates>
+  </xsl:template>
+
   <xsl:template match="rng:element" mode="chunk">
     <xsl:param name="home"/>
     <xsl:param name="prev"/>
     </div>
   </xsl:template>
 
-  <xsl:template match="doc:attributes">
-    <xsl:variable name="attributes" select=".//rng:attribute"/>
-
-    <xsl:variable name="cmnAttr"
-                 select="$attributes[@name='id' and parent::rng:optional]
-                         |$attributes[@name='xml:lang']
-                         |$attributes[@name='xml:base']
-                         |$attributes[@name='remap']
-                         |$attributes[@name='xreflabel']
-                         |$attributes[@name='revisionflag']
-                         |$attributes[@name='arch']
-                         |$attributes[@name='condition']
-                         |$attributes[@name='conformance']
-                         |$attributes[@name='os']
-                         |$attributes[@name='revision']
-                         |$attributes[@name='security']
-                         |$attributes[@name='userlevel']
-                         |$attributes[@name='vendor']
-                         |$attributes[@name='role']
-                         |$attributes[@name='version']"/>
-
-    <xsl:variable name="cmnAttrIdReq"
-                 select="$attributes[@name='id' and not(parent::rng:optional)]
-                         |$attributes[@name='xml:lang']
-                         |$attributes[@name='xml:base']
-                         |$attributes[@name='remap']
-                         |$attributes[@name='xreflabel']
-                         |$attributes[@name='revisionflag']
-                         |$attributes[@name='arch']
-                         |$attributes[@name='condition']
-                         |$attributes[@name='conformance']
-                         |$attributes[@name='os']
-                         |$attributes[@name='revision']
-                         |$attributes[@name='security']
-                         |$attributes[@name='userlevel']
-                         |$attributes[@name='vendor']
-                         |$attributes[@name='role']
-                         |$attributes[@name='version']"/>
-
-    <xsl:variable name="cmnAttrEither" select="$cmnAttr|$cmnAttrIdReq"/>
-
-    <xsl:variable name="cmnLinkAttr"
-                 select="$attributes[@name='href' and $attributes[@name='linkend']]
-                         |$attributes[@name='linkend' and $attributes[@name='href']]"/>
-
-    <xsl:variable name="otherAttr"
-                 select="set:difference($attributes,
-                                        $cmnAttr|$cmnAttrIdReq|$cmnLinkAttr)"/>
-
-    <xsl:choose>
-      <xsl:when test="count($cmnAttr) = 16 and $cmnLinkAttr">
-       <p>Common attributes and common linking attributes.</p>
-      </xsl:when>
-      <xsl:when test="count($cmnAttrIdReq) = 16 and $cmnLinkAttr">
-       <p>Common attributes (ID required) and common linking atttributes.</p>
-      </xsl:when>
-      <xsl:when test="count($cmnAttr) = 16">
-       <p>Common attributes.</p>
-      </xsl:when>
-      <xsl:when test="count($cmnAttrIdReq) = 16">
-       <p>Common attributes (ID required).</p>
-      </xsl:when>
-      <xsl:when test="$cmnLinkAttr">
-       <p>Common linking attributes.</p>
-      </xsl:when>
-    </xsl:choose>
-
-    <xsl:if test="count($cmnAttrEither) != 16 or count($otherAttr) &gt; 0">
+<xsl:template match="doc:attributes">
+  <xsl:variable name="attributes" select=".//rng:attribute"/>
+
+  <xsl:variable name="cmnAttr"
+               select="$attributes[@name='xml:id' and parent::rng:optional]
+                       |$attributes[@name='xml:lang']
+                       |$attributes[@name='xml:base']
+                       |$attributes[@name='remap']
+                       |$attributes[@name='xreflabel']
+                       |$attributes[@name='revisionflag']
+                       |$attributes[@name='arch']
+                       |$attributes[@name='condition']
+                       |$attributes[@name='conformance']
+                       |$attributes[@name='os']
+                       |$attributes[@name='revision']
+                       |$attributes[@name='security']
+                       |$attributes[@name='userlevel']
+                       |$attributes[@name='vendor']
+                       |$attributes[@name='wordsize']
+                       |$attributes[@name='role']
+                       |$attributes[@name='version']"/>
+
+  <xsl:variable name="cmnAttrIdReq"
+               select="$attributes[@name='xml:id' and not(parent::rng:optional)]
+                       |$attributes[@name='xml:lang']
+                       |$attributes[@name='xml:base']
+                       |$attributes[@name='remap']
+                       |$attributes[@name='xreflabel']
+                       |$attributes[@name='revisionflag']
+                       |$attributes[@name='arch']
+                       |$attributes[@name='condition']
+                       |$attributes[@name='conformance']
+                       |$attributes[@name='os']
+                       |$attributes[@name='revision']
+                       |$attributes[@name='security']
+                       |$attributes[@name='userlevel']
+                       |$attributes[@name='vendor']
+                       |$attributes[@name='wordsize']
+                       |$attributes[@name='role']
+                       |$attributes[@name='version']"/>
+
+  <xsl:variable name="cmnAttrEither" select="$cmnAttr|$cmnAttrIdReq"/>
+
+  <xsl:variable name="cmnLinkAttr"
+               select="$attributes[@name='linkend']
+                        |$attributes[@name='xlink:href']
+                        |$attributes[@name='xlink:type']
+                        |$attributes[@name='xlink:role']
+                        |$attributes[@name='xlink:arcrole']
+                        |$attributes[@name='xlink:title']
+                        |$attributes[@name='xlink:show']
+                        |$attributes[@name='xlink:actuate']"/>
+
+  <xsl:variable name="otherAttr"
+               select="set:difference($attributes,
+                                      $cmnAttr|$cmnAttrIdReq|$cmnLinkAttr)"/>
+
+  <xsl:choose>
+    <xsl:when test="count($cmnAttr) = 17 and count($cmnLinkAttr) = 8">
+      <para>Common attributes and common linking attributes.</para>
+    </xsl:when>
+    <xsl:when test="count($cmnAttrIdReq) = 17 and count($cmnLinkAttr) = 8">
+      <para>Common attributes (ID required) and common linking atttributes.</para>
+    </xsl:when>
+    <xsl:when test="count($cmnAttr) = 17">
+      <para>Common attributes.</para>
+    </xsl:when>
+    <xsl:when test="count($cmnAttrIdReq) = 17">
+      <para>Common attributes (ID required).</para>
+    </xsl:when>
+    <xsl:when test="count($cmnLinkAttr) = 8">
+      <para>Common linking attributes.</para>
+    </xsl:when>
+  </xsl:choose>
+
+    <xsl:if test="count($cmnAttrEither) != 17 or count($otherAttr) &gt; 0">
       <p>
        <xsl:choose>
-         <xsl:when test="count($cmnAttr) = 16 
-                         or count($cmnAttrIdReq) = 15
-                         or $cmnLinkAttr">
+         <xsl:when test="count($cmnAttr) = 17 
+                         or count($cmnAttrIdReq) = 17">
            <xsl:text>Additional attributes:</xsl:text>
          </xsl:when>
          <xsl:otherwise>
 
       <ul>
        <xsl:for-each select="rng:interleave/*|*[not(self::rng:interleave)]">
-         <xsl:sort select="descendant-or-self::rng:attribute/@name"/>
+         <xsl:sort select="descendant-or-self::rng:attribute[1]/@name"/>
          <!-- don't bother with common attributes -->
          <xsl:variable name="name" select="descendant-or-self::rng:attribute/@name"/>
          <xsl:choose>
index 4c9623afbd72c122957d6d856777756921127fd5..9e28089d528031b893827a2877da202bd2f79283 100644 (file)
     </xsl:copy>
   </xsl:template>
 
-  <xsl:template match="comment()|processing-instruction()|text()" mode="classify">
+  <xsl:template match="comment()|processing-instruction()|text()"
+               mode="classify">
     <xsl:copy/>
   </xsl:template>
 
 
   <xsl:template match="/" mode="flattenTest">
     <xsl:value-of select="count(//doc:content-model//rng:choice/rng:choice
+                               |//doc:content-model//rng:zeroOrMore[not(*)]
+                               |//doc:content-model//rng:oneOrMore[not(*)]
+                               |//doc:content-model//rng:choice[not(*)]
                                |//doc:content-model//rng:choice[count(*)=1]
                                 |//doc:content-model//rng:zeroOrMore/rng:choice
                                 |//doc:content-model//rng:oneOrMore/rng:choice
     <xsl:apply-templates mode="flatten"/>
   </xsl:template>
 
+  <xsl:template match="rng:zeroOrMore[not(*)]
+                      |rng:oneOrMore[not(*)]
+                      |rng:choice[not(*)]"
+               mode="flatten">
+    <!-- discard them; they must have contained nothing but notAllowed -->
+  </xsl:template>
+
   <xsl:template match="rng:group" mode="flatten">
     <xsl:choose>
       <xsl:when test="ancestor::doc:attributes
 
   <xsl:template match="rng:notAllowed" mode="flatten">
     <xsl:choose>
-      <xsl:when test="parent::rng:choice|parent::rng:zeroOrMore|parent::rng:oneOrMore">
+      <xsl:when test="parent::rng:choice
+                     |parent::rng:zeroOrMore
+                     |parent::rng:oneOrMore">
        <!-- suppress -->
       </xsl:when>
       <xsl:otherwise>