<xsl:template name="anyElement">
<xsl:variable name="apos">'</xsl:variable>
<xsl:variable name="spec" select="ancestor::tei:elementSpec|ancestor::tei:macroSpec"/>
<xsl:variable name="current" select="."/>
<xsl:variable name="disambiguator" as="xs:string">
<xsl:number level="any" format="{$anyElement_disambiguator_format}"/>
</xsl:variable>
<xsl:variable name="id" select="concat('anyElement_', $spec/@ident, $disambiguator )"/>
<xsl:variable name="exclude">
<xsl:choose>
<xsl:when test="@exclude">
<xsl:value-of select="@exclude"/>
</xsl:when>
<xsl:when test="ancestor::tei:schemaSpec/@defaultExceptions">
<xsl:value-of select="ancestor::tei:schemaSpec/@defaultExceptions"/>
</xsl:when>
<xsl:otherwise>http://www.tei-c.org/ns/1.0 teix:egXML</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<define name="{$id}" xmlns="http://relaxng.org/ns/structure/1.0">
<element>
<anyName>
<except>
<xsl:for-each select="distinct-values(tokenize(normalize-space($exclude), '\s+'))">
<xsl:choose>
<xsl:when test=". = 'teix:egXML'">
<name ns="http://www.tei-c.org/ns/Examples">egXML</name>
</xsl:when>
<xsl:when test="matches(.,'\w+:\w+')">
<xsl:choose>
<xsl:when test="namespace-uri-for-prefix(substring-before(.,':'),$current)">
<name ns="{namespace-uri-for-prefix(substring-before(.,':'),$current)}">
<xsl:value-of select="substring-after(.,':')"/>
</name>
</xsl:when>
<xsl:otherwise>
<nsName ns="{.}"/>
</xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:otherwise>
<nsName ns="{.}"/>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
</except>
</anyName>
<zeroOrMore>
<attribute>
<anyName/>
</attribute>
</zeroOrMore>
<zeroOrMore>
<choice>
<text/>
<ref name="{$id}"/>
</choice>
</zeroOrMore>
</element>
<xsl:if test="@require and ancestor::tei:elementSpec">
<xsl:variable name="ns">
<xsl:if test="ancestor::tei:content//tei:*">, 'http://www.tei-c.org/ns/1.0'</xsl:if>
</xsl:variable>
<xsl:variable name="computed-prefix">
<xsl:for-each select="in-scope-prefixes($current)">
<xsl:if test="$spec/@ns = namespace-uri-for-prefix(., $current)">
<xsl:value-of select="."/>
</xsl:if>
</xsl:for-each>
</xsl:variable>
<xsl:variable name="prefix">
<xsl:choose>
<xsl:when test="ancestor::tei:elementSpec/@ns">
<xsl:value-of select="$computed-prefix"/>
</xsl:when>
<xsl:otherwise>tei</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:if test="$spec/@ns">
<ns xmlns="http://purl.oclc.org/dsdl/schematron" prefix="{$prefix}" uri="{ancestor::tei:elementSpec/@ns}"/>
</xsl:if>
<pattern xmlns="http://purl.oclc.org/dsdl/schematron" id="{concat(generate-id(),'-constraint')}">
<rule context="{$prefix}:{ancestor::tei:elementSpec/@ident}">
<report test="descendant::*[not(namespace-uri(.) = ({concat($apos,string-join(tokenize(current()/@require, ' '),concat($apos,', ',$apos)),$apos,$ns)}))]">
<xsl:value-of select="ancestor::tei:elementSpec/@ident"/> descendants must be in the
namespace<xsl:if test="contains(@require, ' ') or $ns ne ''">s</xsl:if><xsl:text>
</xsl:text><xsl:value-of select="concat($apos,string-join(tokenize(current()/@require, ' '),concat($apos,', ',$apos)),$apos,$ns)"/></report>
</rule>
</pattern>
</xsl:if>
</define>
</xsl:template> |