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><!ELEMENT </xsl:text>
- <xsl:value-of select="@name"/>
- <xsl:text> </xsl:text>
- <xsl:apply-templates select="doc:content-model" mode="model"/>
- <xsl:text>> </xsl:text>
-
- <xsl:text><!ATTLIST </xsl:text>
- <xsl:value-of select="@name"/>
- <xsl:text> </xsl:text>
-
- <xsl:if test="$start//rng:ref[@name = $defname]">
- <xsl:text>	xmlns	CDATA #FIXED "http://docbook.org/docbook-ng" </xsl:text>
- <xsl:text>	version	CDATA	#IMPLIED </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>> </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>	</xsl:text>
- <xsl:value-of select="@name"/>
-
- <xsl:text>	</xsl:text>
- <xsl:if test="string-length(@name) < 8">
- <xsl:text>	</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>	</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> </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() > 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() > 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>
<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])]"
<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) > 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) > 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>