]> granicus.if.org Git - docbook-dsssl/commitdiff
Handle elements that are choices; remove choices that contain a single item
authorNorman Walsh <ndw@nwalsh.com>
Wed, 26 May 2004 17:37:38 +0000 (17:37 +0000)
committerNorman Walsh <ndw@nwalsh.com>
Wed, 26 May 2004 17:37:38 +0000 (17:37 +0000)
docbook/relaxng/tools/rngdocxml.xsl

index b3a3b4e754d2d0b4a82feb9529c1413eee587fa5..4c9623afbd72c122957d6d856777756921127fd5 100644 (file)
@@ -7,6 +7,7 @@
                 xmlns:doc="http://nwalsh.com/xmlns/schema-doc/"
                xmlns:s="http://www.ascc.net/xml/schematron"
                 exclude-result-prefixes="exsl ctrl s set"
+                extension-element-prefixes="exsl"
                 version="1.0">
 
   <xsl:output method="xml" encoding="utf-8" indent="yes"/>
        <xsl:when test="ancestor::rng:define[@name=$name]">
          <!-- don't expand recursively -->
        </xsl:when>
-       <xsl:when test="$ref and $ref/rng:element">
+       <xsl:when test="$ref and ($ref/rng:element or $ref/rng:choice/rng:element)">
          <!-- don't expand element patterns -->
        </xsl:when>
        <xsl:when test="$ref and $ref/rng:empty">
          <xsl:apply-templates mode="expand"/>
        </xsl:copy>
       </xsl:when>
-      <xsl:when test="$ref and $ref/rng:element">
+      <xsl:when test="$ref and ($ref/rng:element or $ref/rng:choice/rng:element)">
        <!-- don't expand element patterns -->
        <xsl:copy>
          <xsl:copy-of select="@*"/>
 
   <xsl:template name="flatten">
     <xsl:param name="root"/>
+    <xsl:param name="count" select="1"/>
 
     <xsl:variable name="canFlatten">
       <xsl:apply-templates select="$root" mode="flattenTest"/>
        <xsl:variable name="flattened">
          <xsl:apply-templates select="$root" mode="flatten"/>
        </xsl:variable>
+
        <xsl:call-template name="flatten">
          <xsl:with-param name="root" select="exsl:node-set($flattened)"/>
+         <xsl:with-param name="count" select="$count + 1"/>
        </xsl:call-template>
       </xsl:when>
       <xsl:otherwise>
 
   <xsl:template match="/" mode="flattenTest">
     <xsl:value-of select="count(//doc:content-model//rng:choice/rng:choice
+                               |//doc:content-model//rng:choice[count(*)=1]
                                 |//doc:content-model//rng:zeroOrMore/rng:choice
                                 |//doc:content-model//rng:oneOrMore/rng:choice
                                 |//doc:content-model//rng:zeroOrMore/rng:zeroOrMore
   </xsl:template>
 
   <xsl:template match="doc:content-model//rng:choice/rng:choice
+                      |doc:content-model//rng:choice[count(*)=1]
                       |doc:content-model//rng:zeroOrMore/rng:choice
                       |doc:content-model//rng:oneOrMore/rng:choice
                       |doc:content-model//rng:zeroOrMore/rng:zeroOrMore
     </xsl:choose>
   </xsl:template>
 
+  <xsl:template match="rng:choice[count(*)=1]" mode="flatten">
+    <xsl:apply-templates mode="flatten"/>
+  </xsl:template>
+
   <xsl:template match="*" mode="flatten">
     <xsl:copy>
       <xsl:copy-of select="@*"/>