TEI stylesheet for making Relax NG schema from ODD
This software is dual-licensed:
1. Distributed under a Creative Commons Attribution-ShareAlike 3.0
Unported License http://creativecommons.org/licenses/by-sa/3.0/
2. http://www.opensource.org/licenses/BSD-2-Clause
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
This software is provided by the copyright holders and contributors
"as is" and any express or implied warranties, including, but not
limited to, the implied warranties of merchantability and fitness for
a particular purpose are disclaimed. In no event shall the copyright
holder or contributors be liable for any direct, indirect, incidental,
special, exemplary, or consequential damages (including, but not
limited to, procurement of substitute goods or services; loss of use,
data, or profits; or business interruption) however caused and on any
theory of liability, whether in contract, strict liability, or tort
(including negligence or otherwise) arising in any way out of the use
of this software, even if advised of the possibility of such damage.
<xsl:template name="schemaSpecBody"><xsl:variable name="original" select="."/><xsl:variable name="pass1"><root><xsl:if test="$verbose='true'"><xsl:message>start importing moduleRef components</xsl:message></xsl:if><xsl:apply-templates mode="tangle" select="tei:moduleRef"/><xsl:for-each select="tei:macroSpec"><xsl:apply-templates mode="tangle" select="."/></xsl:for-each><xsl:apply-templates mode="tangle" select="tei:elementSpec|tei:classSpec"/><xsl:choose><xsl:when test="@start and @start=''"/><xsl:when test="@start"><start xmlns="http://relaxng.org/ns/structure/1.0"><choice><xsl:for-each select="tokenize(@start,' ')"><ref xmlns="http://relaxng.org/ns/structure/1.0" name="{.}"/></xsl:for-each></choice></start></xsl:when><xsl:when test="key('IDENTS','teiCorpus')"><start xmlns="http://relaxng.org/ns/structure/1.0"><choice><ref name="{$generalPrefix}TEI"/><ref name="{$generalPrefix}teiCorpus"/></choice></start></xsl:when><xsl:otherwise><start xmlns="http://relaxng.org/ns/structure/1.0"><ref name="{$generalPrefix}TEI"/></start></xsl:otherwise></xsl:choose></root></xsl:variable><!-- in 2nd and 3rd passes, throw away any RNG <define> elements
which do not have a <ref>, any <ref> which has no <define>
to point to, and any empty <choice> --><xsl:variable name="pass2"><xsl:for-each select="$pass1/root"><root><xsl:apply-templates mode="pass2"/></root></xsl:for-each></xsl:variable><xsl:for-each select="$pass2/root"><xsl:apply-templates mode="pass3"/></xsl:for-each></xsl:template>
<xsl:template name="copyright"><xsl:for-each select="/tei:TEI/tei:teiHeader/tei:fileDesc/tei:publicationStmt/tei:availability"><xsl:if test="count(tei:licence)>1"><xsl:text>This material is dual-licensed.
</xsl:text></xsl:if><xsl:apply-templates/></xsl:for-each></xsl:template>
<xsl:template name="NameList"><!-- walk over all the elementSpec elements and make list of
elements --><xsl:for-each select="key('ELEMENTDOCS',1)"><xsl:sort select="@ident"/><define xmlns="http://relaxng.org/ns/structure/1.0" combine="choice" name="{@ident}"><notAllowed/></define></xsl:for-each></xsl:template>
<xsl:template match="rng:list|rng:element" mode="pass3"><xsl:element name="{name()}" xmlns="http://relaxng.org/ns/structure/1.0"><xsl:apply-templates select="@*" mode="pass3"/><xsl:variable name="Contents"><xsl:apply-templates select="*|processing-instruction()|comment()|text()" mode="pass3"/></xsl:variable><xsl:choose><xsl:when test="$Contents//rng:text or $Contents//rng:ref or $Contents//rng:anyName or $Contents//rng:attribute or $Contents//rng:data or $Contents//rng:name or $Contents//rng:value"><xsl:copy-of select="$Contents"/></xsl:when><xsl:otherwise><xsl:copy-of select="$Contents/a:*"/><rng:empty/></xsl:otherwise></xsl:choose></xsl:element></xsl:template>
<xsl:template match="rng:start/rng:choice" mode="pass3"><!-- look at start patterns and see if they need prepending with
prefix --><choice xmlns="http://relaxng.org/ns/structure/1.0"><xsl:for-each select="rng:ref"><xsl:variable name="name" select="if (key('DEFED',@name)) then @name else if (key('DEFED',concat($generalPrefix,@name))) then concat($generalPrefix,@name) else ''"/><xsl:if test="not($name='')"><ref xmlns="http://relaxng.org/ns/structure/1.0" name="{$name}"/></xsl:if></xsl:for-each></choice></xsl:template>
<xsl:function name="tei:generateIndicators"><xsl:param name="min"/><xsl:param name="max"/><xsl:choose><xsl:when test="$min='0' and $max='1'">optional</xsl:when><xsl:when test="$min='0' and not($max)">optional</xsl:when><xsl:when test="$min='1' and $max='unbounded'">oneOrMore</xsl:when><xsl:when test="not($min) and $max='unbounded'">oneOrMore</xsl:when><xsl:when test="$min='0' and $max='unbounded'">zeroOrMore</xsl:when><xsl:otherwise/></xsl:choose></xsl:function>