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="@*"/>