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 match="/"><xsl:if test="$autoGlobal='true'"><xsl:message>NOTE: all TEI elements will have global attributes added automatically</xsl:message></xsl:if><!--
<xsl:result-document href="/tmp/foo.xml">
<xsl:copy-of select="$ODD"/>
</xsl:result-document>
--><xsl:for-each select="$ODD"><xsl:apply-templates mode="odd2odd-pass1"/></xsl:for-each></xsl:template>
<xsl:template match="tei:schemaSpec" mode="odd2odd-pass0"><xsl:if test="@ident=$selectedSchema or ($selectedSchema='' and not(preceding-sibling::tei:schemaSpec))"><xsl:copy><xsl:copy-of select="@*"/><xsl:choose><xsl:when test="@source"><xsl:if test="$verbose='true'"><xsl:message>Source for TEI is<xsl:value-of select="@source"/></xsl:message></xsl:if></xsl:when><xsl:otherwise><xsl:if test="$verbose='true'"><xsl:message>Source for TEI will be set to<xsl:value-of select="$DEFAULTSOURCE"/></xsl:message></xsl:if><xsl:attribute name="source"><xsl:value-of select="$DEFAULTSOURCE"/></xsl:attribute></xsl:otherwise></xsl:choose><xsl:apply-templates select="*|text()|processing-instruction()" mode="odd2odd-pass0"/></xsl:copy></xsl:if></xsl:template>
<xsl:template match="tei:schemaSpec" mode="odd2odd-pass1"><xsl:variable name="sourceDoc" select="tei:workOutSource(.)"/><xsl:variable name="oddsource"><xsl:copy><xsl:copy-of select="@*"/><xsl:if test="$verbose='true'"><xsl:message>Schema<xsl:value-of select="@ident"/></xsl:message></xsl:if><!--
it is important to process "tei" and "core" first
because of the order of declarations
--><xsl:for-each select="tei:moduleRef[@key='tei']"><xsl:call-template name="odd2odd-expandModule"><xsl:with-param name="Source" select="$sourceDoc" tunnel="yes"/></xsl:call-template></xsl:for-each><xsl:for-each select="tei:moduleRef[@key='core']"><xsl:call-template name="odd2odd-expandModule"><xsl:with-param name="Source" select="$sourceDoc" tunnel="yes"/></xsl:call-template></xsl:for-each><xsl:for-each select="tei:moduleRef[@key]"><xsl:if test="not(@key='tei' or @key='core')"><xsl:call-template name="odd2odd-expandModule"><xsl:with-param name="Source" select="$sourceDoc" tunnel="yes"/></xsl:call-template></xsl:if></xsl:for-each><xsl:for-each select="tei:macroRef|tei:classRef|tei:elementRef"><xsl:call-template name="odd2odd-followRef"></xsl:call-template></xsl:for-each><xsl:for-each select="tei:classSpec[@mode='add' or not(@mode)]"><xsl:call-template name="odd2odd-createCopy"><xsl:with-param name="Source" select="$sourceDoc" tunnel="yes"/></xsl:call-template></xsl:for-each><xsl:for-each select="tei:macroSpec[@mode='add' or not(@mode)]"><xsl:call-template name="odd2odd-createCopy"><xsl:with-param name="Source" select="$sourceDoc" tunnel="yes"/></xsl:call-template></xsl:for-each><xsl:for-each select="tei:elementSpec[@mode='add' or not(@mode)]"><xsl:call-template name="odd2odd-createCopy"><xsl:with-param name="Source" select="$sourceDoc" tunnel="yes"/></xsl:call-template></xsl:for-each><xsl:apply-templates mode="odd2odd-justcopy" select="tei:moduleRef[@url]"/></xsl:copy></xsl:variable><xsl:for-each select="$oddsource"><xsl:apply-templates mode="odd2odd-pass2"/></xsl:for-each><!-- constraints --><xsl:apply-templates mode="odd2odd-copy" select="tei:constraintSpec"/></xsl:template>
<xsl:template name="odd2odd-amINeeded"><!--
How can a class be ok?
a) if an element is a member of it
b) if its referred to in a content model
c) if some other class is a member of it, and that class is OK
--><xsl:variable name="k" select="@ident"/><xsl:choose><xsl:when test="$autoGlobal='true' and starts-with(@ident,'att.global')">y</xsl:when><xsl:when test="self::tei:classSpec and $stripped='true'">y</xsl:when><xsl:when test="key('odd2odd-ELEMENT_MEMBERED',$k)">y</xsl:when><xsl:when test="key('odd2odd-REFED',$k)">y</xsl:when><xsl:when test="key('odd2odd-CLASS_MEMBERED',$k)"><xsl:for-each select="key('odd2odd-CLASS_MEMBERED',$k)"><xsl:call-template name="odd2odd-amINeeded"/></xsl:for-each></xsl:when></xsl:choose></xsl:template>
<xsl:template name="odd2odd-checkObject"><xsl:param name="why"/><xsl:param name="Source" tunnel="yes"/><!--
for every object
- if its in DELETE list, ignore
- if its in REPLACE list, use that
- if its in CHANGE list
(do the hard merge bit)
- otherwise copy
done
--><xsl:variable name="Current" select="."/><xsl:variable name="specName"><xsl:choose><xsl:when test="@ns"><xsl:value-of select="@ns"/></xsl:when><xsl:when test="ancestor::tei:schemaSpec/@ns"><xsl:value-of select="ancestor::tei:schemaSpec/@ns"/></xsl:when></xsl:choose><xsl:value-of select="@ident"/></xsl:variable><xsl:variable name="N" select="local-name(.)"/><xsl:for-each select="$ODD"><xsl:choose><xsl:when test="key('odd2odd-DELETE',$specName)"><xsl:if test="$verbose='true'"><xsl:message>Phase 1: remove<xsl:value-of select="$specName"/></xsl:message></xsl:if></xsl:when><xsl:when test="key('odd2odd-REPLACE',$specName)"><xsl:if test="$verbose='true'"><xsl:message>Phase 1: replace<xsl:value-of select="$specName"/></xsl:message></xsl:if><xsl:apply-templates mode="odd2odd-copy" select="key('odd2odd-REPLACE',$specName)"/></xsl:when><xsl:when test="key('odd2odd-CHANGE',$specName)"><xsl:if test="$verbose='true'"><xsl:message>Phase 1: change<xsl:value-of select="$specName"/></xsl:message></xsl:if><xsl:apply-templates mode="odd2odd-change" select="$Current"/></xsl:when><xsl:otherwise><xsl:if test="$verbose='true'"><xsl:message>Phase 1: include<xsl:value-of select="$specName"/>from<xsl:value-of select="$Source"/>(<xsl:value-of select="$why"/>)</xsl:message></xsl:if><xsl:apply-templates mode="odd2odd-copy" select="$Current"/></xsl:otherwise></xsl:choose></xsl:for-each></xsl:template>
<xsl:template match="tei:elementSpec" mode="odd2odd-change"><xsl:variable name="elementName"><xsl:value-of select="concat(@ns,@ident)"/></xsl:variable><xsl:variable name="ORIGINAL" select="."/><xsl:copy><xsl:attribute name="rend">change</xsl:attribute><xsl:apply-templates mode="odd2odd-change" select="@*"/><!--
For each element, go through most of the sections one by one
and see if they are present in the change mode version.
If so, use them as is. The constraints and attributes are identifiable
for change individually.
--><xsl:for-each select="$ODD"><xsl:for-each select="key('odd2odd-CHANGE',$elementName)"><xsl:if test="$verbose='true'"><xsl:message>Change<xsl:value-of select="$elementName"/></xsl:message></xsl:if><xsl:copy-of select="@ns"/><!-- if there is an altIdent, use it --><xsl:apply-templates mode="odd2odd-justcopy" select="tei:altIdent"/><!-- equiv, gloss, desc trio --><xsl:choose><xsl:when test="tei:equiv"><xsl:apply-templates mode="odd2odd-copy" select="tei:equiv"/></xsl:when><xsl:otherwise><xsl:for-each select="$ORIGINAL"><xsl:apply-templates mode="odd2odd-copy" select="tei:equiv"/></xsl:for-each></xsl:otherwise></xsl:choose><xsl:choose><xsl:when test="tei:gloss"><xsl:apply-templates mode="odd2odd-justcopy" select="tei:gloss"/></xsl:when><xsl:otherwise><xsl:for-each select="$ORIGINAL"><xsl:apply-templates mode="odd2odd-justcopy" select="tei:gloss"/></xsl:for-each></xsl:otherwise></xsl:choose><xsl:choose><xsl:when test="$stripped='true'"/><xsl:when test="tei:desc"><xsl:apply-templates mode="odd2odd-justcopy" select="tei:desc"/></xsl:when><xsl:otherwise><xsl:for-each select="$ORIGINAL"><xsl:apply-templates mode="odd2odd-justcopy" select="tei:desc"/></xsl:for-each></xsl:otherwise></xsl:choose><!-- classes --><classes xmlns="http://www.tei-c.org/ns/1.0"><xsl:choose><xsl:when test="tei:classes[@mode='change']"><xsl:for-each select="tei:classes/tei:memberOf"><xsl:choose><xsl:when test="@mode='delete'"/><xsl:when test="@mode='add' or not (@mode)"><memberOf key="{@key}"><xsl:copy-of select="@min|@max"/></memberOf></xsl:when></xsl:choose></xsl:for-each><xsl:for-each select="$ORIGINAL"><xsl:for-each select="tei:classes/tei:memberOf"><xsl:variable name="me"><xsl:value-of select="@key"/></xsl:variable><xsl:variable name="metoo"><xsl:value-of select="concat(../../@ident,@key)"/></xsl:variable><xsl:for-each select="$ODD"><xsl:choose><xsl:when test="key('odd2odd-DELETE',$me)"></xsl:when><xsl:when test="key('odd2odd-MEMBEROFDELETE',$metoo)"></xsl:when><xsl:when test="key('odd2odd-MEMBEROFADD',$metoo)"></xsl:when><xsl:otherwise><memberOf key="{$me}"/></xsl:otherwise></xsl:choose></xsl:for-each></xsl:for-each></xsl:for-each></xsl:when><xsl:when test="tei:classes"><xsl:for-each select="tei:classes/tei:memberOf"><xsl:copy-of select="."/></xsl:for-each></xsl:when><xsl:otherwise><xsl:for-each select="$ORIGINAL"><xsl:for-each select="tei:classes/tei:memberOf"><xsl:variable name="me"><xsl:value-of select="@key"/></xsl:variable><xsl:for-each select="$ODD"><xsl:if test="not(key('odd2odd-DELETE',$me))"><memberOf key="{$me}"/></xsl:if></xsl:for-each></xsl:for-each></xsl:for-each></xsl:otherwise></xsl:choose></classes><!-- valList --><xsl:choose><xsl:when test="tei:valList[@mode='delete']"/><xsl:when test="tei:valList"><xsl:apply-templates mode="odd2odd-copy" select="tei:valList[1]"/></xsl:when><xsl:otherwise><xsl:for-each select="$ORIGINAL"><xsl:apply-templates mode="odd2odd-copy" select="tei:valList"/></xsl:for-each></xsl:otherwise></xsl:choose><!-- element content --><content xmlns="http://www.tei-c.org/ns/1.0"><xsl:choose><xsl:when test="tei:content/rng:*"><xsl:apply-templates mode="odd2odd-copy" select="tei:content/*"/></xsl:when><xsl:when test="tei:content/tei:*"><xsl:apply-templates mode="odd2odd-copy" select="tei:content/*"/></xsl:when><xsl:otherwise><xsl:for-each select="$ORIGINAL"><xsl:apply-templates mode="odd2odd-copy" select="tei:content/*"/></xsl:for-each></xsl:otherwise></xsl:choose></content><!-- element constraints --><xsl:call-template name="odd2odd-processConstraints"><xsl:with-param name="ORIGINAL" select="$ORIGINAL"/><xsl:with-param name="elementName" select="$elementName"/></xsl:call-template><!-- attList --><attList xmlns="http://www.tei-c.org/ns/1.0"><xsl:apply-templates mode="odd2odd-justcopy" select="tei:attList/@org"/><xsl:call-template name="odd2odd-processAttributes"><xsl:with-param name="ORIGINAL" select="$ORIGINAL"/><xsl:with-param name="elementName" select="$elementName"/></xsl:call-template></attList><!-- exemplum, remarks and listRef are either replacements or not --><xsl:choose><xsl:when test="$stripped='true'"/><xsl:when test="tei:exemplum"><xsl:apply-templates mode="odd2odd-justcopy" select="tei:exemplum"/></xsl:when><xsl:otherwise><xsl:for-each select="$ORIGINAL"><xsl:apply-templates mode="odd2odd-justcopy" select="tei:exemplum"/></xsl:for-each></xsl:otherwise></xsl:choose><xsl:choose><xsl:when test="$stripped='true'"/><xsl:when test="tei:remarks"><xsl:apply-templates mode="odd2odd-justcopy" select="tei:remarks"/></xsl:when><xsl:otherwise><xsl:for-each select="$ORIGINAL"><xsl:apply-templates mode="odd2odd-justcopy" select="tei:remarks"/></xsl:for-each></xsl:otherwise></xsl:choose><xsl:choose><xsl:when test="tei:listRef"><xsl:apply-templates mode="odd2odd-justcopy" select="tei:listRef"/></xsl:when><xsl:otherwise><xsl:for-each select="$ORIGINAL"><xsl:apply-templates mode="odd2odd-justcopy" select="tei:listRef"/></xsl:for-each></xsl:otherwise></xsl:choose></xsl:for-each></xsl:for-each></xsl:copy></xsl:template>
<xsl:template match="tei:macroSpec" mode="odd2odd-change"><xsl:variable name="elementName"><xsl:value-of select="concat(@ns,@ident)"/></xsl:variable><xsl:variable name="ORIGINAL" select="."/><xsl:copy><xsl:attribute name="rend">change</xsl:attribute><xsl:apply-templates mode="odd2odd-change" select="@*"/><!--
For each macro, go through most of the sections one by one
and see if they are present in the change mode version.
If so, use them as is.
--><xsl:for-each select="$ODD"><xsl:for-each select="key('odd2odd-CHANGE',$elementName)"><!-- if there is an altIdent, use it --><xsl:apply-templates mode="odd2odd-justcopy" select="tei:altIdent"/><!-- equiv, gloss, desc trio --><xsl:choose><xsl:when test="$stripped='true'"/><xsl:when test="tei:equiv"><xsl:apply-templates mode="odd2odd-copy" select="tei:equiv"/></xsl:when><xsl:otherwise><xsl:for-each select="$ORIGINAL"><xsl:apply-templates mode="odd2odd-copy" select="tei:equiv"/></xsl:for-each></xsl:otherwise></xsl:choose><xsl:choose><xsl:when test="tei:gloss"><xsl:apply-templates mode="odd2odd-justcopy" select="tei:gloss"/></xsl:when><xsl:otherwise><xsl:for-each select="$ORIGINAL"><xsl:apply-templates mode="odd2odd-justcopy" select="tei:gloss"/></xsl:for-each></xsl:otherwise></xsl:choose><xsl:choose><xsl:when test="$stripped='true'"/><xsl:when test="tei:desc"><xsl:apply-templates mode="odd2odd-justcopy" select="tei:desc"/></xsl:when><xsl:otherwise><xsl:for-each select="$ORIGINAL"><xsl:apply-templates mode="odd2odd-justcopy" select="tei:desc"/></xsl:for-each></xsl:otherwise></xsl:choose><!-- content --><xsl:choose><xsl:when test="tei:content"><xsl:apply-templates mode="odd2odd-justcopy" select="tei:content"/></xsl:when><xsl:otherwise><xsl:for-each select="$ORIGINAL"><xsl:apply-templates mode="odd2odd-copy" select="tei:content"/></xsl:for-each></xsl:otherwise></xsl:choose><xsl:choose><xsl:when test="tei:valList"><xsl:apply-templates mode="odd2odd-justcopy" select="tei:valList[1]"/></xsl:when><xsl:when test="tei:stringVal"><xsl:apply-templates mode="odd2odd-justcopy" select="tei:stringVal"/></xsl:when><xsl:otherwise><xsl:for-each select="$ORIGINAL"><xsl:apply-templates mode="odd2odd-copy" select="tei:stringVal"/></xsl:for-each></xsl:otherwise></xsl:choose><!-- exemplum, remarks and listRef are either replacements or not --><xsl:choose><xsl:when test="$stripped='true'"/><xsl:when test="tei:exemplum"><xsl:apply-templates mode="odd2odd-justcopy" select="tei:exemplum"/></xsl:when><xsl:otherwise><xsl:for-each select="$ORIGINAL"><xsl:apply-templates mode="odd2odd-justcopy" select="tei:exemplum"/></xsl:for-each></xsl:otherwise></xsl:choose><xsl:choose><xsl:when test="tei:remarks"><xsl:apply-templates mode="odd2odd-justcopy" select="tei:remarks"/></xsl:when><xsl:otherwise><xsl:for-each select="$ORIGINAL"><xsl:apply-templates mode="odd2odd-justcopy" select="tei:remarks"/></xsl:for-each></xsl:otherwise></xsl:choose><xsl:choose><xsl:when test="$stripped='true'"/><xsl:when test="tei:listRef"><xsl:apply-templates mode="odd2odd-justcopy" select="tei:listRef"/></xsl:when><xsl:otherwise><xsl:for-each select="$ORIGINAL"><xsl:apply-templates mode="odd2odd-justcopy" select="tei:listRef"/></xsl:for-each></xsl:otherwise></xsl:choose></xsl:for-each></xsl:for-each></xsl:copy></xsl:template>
<xsl:template match="tei:classSpec" mode="odd2odd-change"><xsl:variable name="className"><xsl:value-of select="concat(@ns,@ident)"/></xsl:variable><xsl:variable name="ORIGINAL" select="."/><xsl:copy><xsl:attribute name="rend">change</xsl:attribute><xsl:apply-templates mode="odd2odd-change" select="@*"/><!-- for each section of the class spec,
go through the sections one by one
and see if they are present in the change mode version --><xsl:for-each select="$ODD"><xsl:for-each select="key('odd2odd-CHANGE',$className)"><!-- context is now a classSpec in change mode in the ODD spec --><!-- description --><xsl:choose><xsl:when test="$stripped='true'"/><xsl:when test="tei:desc"><xsl:apply-templates mode="odd2odd-justcopy" select="tei:desc"/></xsl:when><xsl:otherwise><xsl:for-each select="$ORIGINAL"><xsl:apply-templates mode="odd2odd-justcopy" select="tei:desc"/></xsl:for-each></xsl:otherwise></xsl:choose><!-- classes --><classes xmlns="http://www.tei-c.org/ns/1.0"><xsl:choose><xsl:when test="tei:classes[@mode='change']"><xsl:for-each select="tei:classes/tei:memberOf"><xsl:choose><xsl:when test="@mode='delete'"/><xsl:when test="@mode='add' or not (@mode)"><memberOf key="{@key}"/></xsl:when></xsl:choose></xsl:for-each><xsl:for-each select="$ORIGINAL"><xsl:for-each select="tei:classes/tei:memberOf"><xsl:variable name="me"><xsl:value-of select="@key"/></xsl:variable><xsl:variable name="metoo"><xsl:value-of select="concat(../../@ident,@key)"/></xsl:variable><xsl:for-each select="$ODD"><xsl:choose><xsl:when test="key('odd2odd-DELETE',$me)"></xsl:when><xsl:when test="key('odd2odd-MEMBEROFDELETE',$metoo)"></xsl:when><xsl:when test="key('odd2odd-MEMBEROFADD',$metoo)"></xsl:when><xsl:otherwise><memberOf key="{$me}"/></xsl:otherwise></xsl:choose></xsl:for-each></xsl:for-each></xsl:for-each></xsl:when><xsl:when test="tei:classes"><xsl:for-each select="tei:classes/tei:memberOf"><xsl:copy-of select="."/></xsl:for-each></xsl:when><xsl:otherwise><xsl:for-each select="$ORIGINAL"><xsl:for-each select="tei:classes/tei:memberOf"><xsl:variable name="me"><xsl:value-of select="@key"/></xsl:variable><xsl:for-each select="$ODD"><xsl:if test="not(key('odd2odd-DELETE',$me))"><memberOf key="{$me}"/></xsl:if></xsl:for-each></xsl:for-each></xsl:for-each></xsl:otherwise></xsl:choose></classes><!-- attList --><attList xmlns="http://www.tei-c.org/ns/1.0"><xsl:call-template name="odd2odd-processAttributes"><xsl:with-param name="ORIGINAL" select="$ORIGINAL"/><xsl:with-param name="elementName" select="''"/></xsl:call-template><xsl:apply-templates mode="odd2odd-justcopy" select="tei:attList/tei:attRef"/></attList></xsl:for-each></xsl:for-each></xsl:copy></xsl:template>
<xsl:template name="odd2odd-simplifyRelax"><xsl:variable name="element"><xsl:value-of select="local-name(.)"/></xsl:variable><!--
for each RELAX NG content model,
remove reference to any elements which have been
deleted, or to classes which are empty.
This may make the container empty,
so that is only put back in if there is some content
--><xsl:variable name="contents"><WHAT><xsl:for-each select="a:*|rng:*|processing-instruction()"><xsl:choose><xsl:when test="self::a:*"><xsl:copy-of select="."/></xsl:when><xsl:when test="self::processing-instruction()"><xsl:copy-of select="."/></xsl:when><xsl:when test="self::rng:element"><element xmlns="http://relaxng.org/ns/structure/1.0"><xsl:copy-of select="@*"/><xsl:apply-templates mode="odd2odd-copy"/></element></xsl:when><xsl:when test="self::rng:name"><name xmlns="http://relaxng.org/ns/structure/1.0"><xsl:copy-of select="@*"/><xsl:apply-templates mode="odd2odd-copy"/></name></xsl:when><xsl:when test="self::rng:attribute"><attribute xmlns="http://relaxng.org/ns/structure/1.0"><xsl:copy-of select="@*"/><xsl:apply-templates mode="odd2odd-copy"/></attribute></xsl:when><xsl:when test="self::rng:data"><data xmlns="http://relaxng.org/ns/structure/1.0"><xsl:copy-of select="@*"/><xsl:apply-templates mode="odd2odd-copy"/></data></xsl:when><xsl:when test="self::rng:text"><text xmlns="http://relaxng.org/ns/structure/1.0"/></xsl:when><xsl:when test="self::rng:value"><value xmlns="http://relaxng.org/ns/structure/1.0"><xsl:apply-templates/></value></xsl:when><xsl:when test="self::rng:ref"><xsl:variable name="N" select="@name"/><xsl:for-each select="$ODD"><xsl:choose><xsl:when test="$stripped='true'"><ref xmlns="http://relaxng.org/ns/structure/1.0" name="{$N}"/></xsl:when><xsl:when test="key('odd2odd-DELETE',$N)"/><xsl:otherwise><ref xmlns="http://relaxng.org/ns/structure/1.0" name="{$N}"/></xsl:otherwise></xsl:choose></xsl:for-each></xsl:when><xsl:otherwise><xsl:call-template name="odd2odd-simplifyRelax"/></xsl:otherwise></xsl:choose></xsl:for-each></WHAT></xsl:variable><xsl:variable name="entCount"><xsl:for-each select="$contents/WHAT"><xsl:value-of select="count(*)"/></xsl:for-each></xsl:variable><xsl:for-each select="$contents/WHAT"><xsl:choose><xsl:when test="$entCount=1 and local-name(*)=$element"><xsl:copy-of select="*|@*|text()|processing-instruction()"/></xsl:when><xsl:when test="$element='optional' and $entCount=1 and rng:zeroOrMore"><xsl:copy-of select="*|@*|text()|processing-instruction()"/></xsl:when><xsl:when test="$element='optional' and $entCount=1 and rng:oneOrMore"><xsl:copy-of select="*|@*|text()|processing-instruction()"/></xsl:when><xsl:when test="$element='oneOrMore' and $entCount=1 and rng:zeroOrMore"><oneOrMore xmlns="http://relaxng.org/ns/structure/1.0"><xsl:copy-of select="rng:zeroOrMore/*"/></oneOrMore></xsl:when><xsl:when test="self::rng:zeroOrMore/rng:ref/@name='model.global' and preceding-sibling::rng:*[1][self::rng:zeroOrMore/rng:ref/@name='model.global']"/><xsl:when test="$entCount>0 or $stripped='true'"><xsl:element xmlns="http://relaxng.org/ns/structure/1.0" name="{$element}"><xsl:copy-of select="*|@*|text()|processing-instruction()"/></xsl:element></xsl:when></xsl:choose></xsl:for-each></xsl:template>
<xsl:template name="odd2odd-classAttributes"><xsl:param name="elementName"/><xsl:param name="className"/><xsl:param name="whence"/><xsl:param name="Source" tunnel="yes"/><!--
On entry, we are sitting on an <elementSpec> or <classSpec>
and seeing if we can pick up some attributes for
$elementName. We travel to the ODD first
to see if it has some overrides
--><xsl:for-each select="$ODD"><xsl:choose><xsl:when test="key('odd2odd-MEMBEROFDELETE',concat($elementName,$className))"></xsl:when><!-- the class is referenced in the ODD and has redefined <classes>--><xsl:when test="key('odd2odd-ATTCLASSES',$className)/tei:classes"><xsl:for-each select="key('odd2odd-ATTCLASSES',$className)"><xsl:call-template name="odd2odd-processClassAttributes"><xsl:with-param name="elementName" select="$elementName"/><xsl:with-param name="className" select="$className"/><xsl:with-param name="whence" select="$whence"/><xsl:with-param name="fromODD">true</xsl:with-param></xsl:call-template></xsl:for-each></xsl:when><!-- the class is referenced in the ODD and has redefined <attList>--><xsl:when test="key('odd2odd-ATTCLASSES',$className)/tei:attList"><xsl:for-each select="key('odd2odd-ATTCLASSES',$className)"><xsl:call-template name="odd2odd-processClassAttributes"><xsl:with-param name="elementName" select="$elementName"/><xsl:with-param name="className" select="$className"/><xsl:with-param name="whence" select="$whence"/><xsl:with-param name="fromODD">true</xsl:with-param></xsl:call-template></xsl:for-each></xsl:when><!-- otherwise, we'll revert to source
(assuming the class is of type 'atts')
--><xsl:otherwise><xsl:for-each select="document($Source)/tei:TEI"><xsl:for-each select="key('odd2odd-ATTCLASSES',$className)"><xsl:call-template name="odd2odd-processClassAttributes"><xsl:with-param name="elementName" select="$elementName"/><xsl:with-param name="className" select="$className"/><xsl:with-param name="whence" select="$whence"/><xsl:with-param name="fromODD">false</xsl:with-param></xsl:call-template></xsl:for-each></xsl:for-each></xsl:otherwise></xsl:choose></xsl:for-each></xsl:template>
<xsl:template name="odd2odd-processClassAttributes"><xsl:param name="elementName"/><xsl:param name="className"/><xsl:param name="fromODD">false</xsl:param><xsl:param name="whence"/><xsl:param name="Source" tunnel="yes"/><!-- we are sitting on a attribute classSpec, could be in the ODD
or could be in the source --><xsl:variable name="M" select="@module"/><!-- decide whether to proceed with this class at all. if we don't
include this class specifically, don't have this module, or we
have deleted the class,
we can bypass it now.--><xsl:variable name="use"><xsl:choose><xsl:when test="$fromODD='true' and (not(@mode) or @mode='add')"><xsl:text>true</xsl:text></xsl:when><xsl:when test="not(@module)"><xsl:text>true</xsl:text></xsl:when><xsl:otherwise><xsl:for-each select="$ODD"><xsl:choose><xsl:when test="key('odd2odd-DELETE',$className)">false</xsl:when><xsl:when test="key('odd2odd-CLASSREFS',$className)">true</xsl:when><xsl:when test="key('odd2odd-MODULES',$M)"><xsl:text>true</xsl:text></xsl:when><xsl:otherwise>false</xsl:otherwise></xsl:choose></xsl:for-each></xsl:otherwise></xsl:choose></xsl:variable><!-- DEBUG--><!--
<xsl:message>START <xsl:value-of select="$whence"/>: <xsl:value-of select="$elementName"/> + <xsl:value-of
select="$className"/> [<xsl:value-of select="$M"/>] + <xsl:value-of
select="$fromODD"/>, so use=<xsl:value-of select="$use"/></xsl:message>
--><xsl:if test="$use='true'"><!--
We need to put in the class attributes. We'll
use the value of $fromODD to see whether this is in the
current ODD or the source.
a) the class is new in this customization, add all attributes regardless
b) the class is marked for deletion. do nothing
c) the class is marked for replacement. reference attributes from the replacement
d) the class is marked for change. compare attributes (tedious)
e) the class has no replacement; reference its attributes
In each case, once we have a potential attribute, we have to check
back to see if it is changed in the element (mergeClassAttribute)
First, establish whether any attributes in the class,
inherited or otherwise, are changed in the ODD. We will
use this information later
--><xsl:variable name="anyChanged"><xsl:choose><xsl:when test="$fromODD='false'"><xsl:call-template name="odd2odd-checkClassAttribute"><xsl:with-param name="element" select="$elementName"/></xsl:call-template></xsl:when><xsl:otherwise><xsl:for-each select="document($Source)/tei:TEI"><xsl:for-each select="key('odd2odd-ATTCLASSES',$className)"><xsl:call-template name="odd2odd-checkClassAttribute"><xsl:with-param name="element" select="$elementName"/></xsl:call-template></xsl:for-each></xsl:for-each></xsl:otherwise></xsl:choose></xsl:variable><!--
<xsl:message>Class <xsl:value-of select="$className"/>, element
<xsl:value-of select="$elementName"/>: has changes: <xsl:value-of
select="$anyChanged"/></xsl:message>
--><xsl:choose><!-- a) new class in ODD --><xsl:when test="$fromODD='true' and (not(@mode) or @mode='add')"><attRef xmlns="http://www.tei-c.org/ns/1.0" n="1" name="{$className}.attributes"/></xsl:when><!-- b) its deleted --><xsl:when test="@mode='delete'"/><!-- c) its a replacement --><xsl:when test="@mode='replace'"><xsl:for-each select="tei:attList/tei:attDef"><xsl:call-template name="odd2odd-mergeClassAttribute"><xsl:with-param name="source">1</xsl:with-param><xsl:with-param name="element" select="$elementName"/><xsl:with-param name="class" select="$className"/><xsl:with-param name="fromODD"><xsl:value-of select="$fromODD"/></xsl:with-param></xsl:call-template></xsl:for-each><xsl:for-each select="tei:attList/tei:attList"><attList xmlns="http://www.tei-c.org/ns/1.0"><xsl:copy-of select="@org"/><xsl:for-each select="tei:attDef"><xsl:call-template name="odd2odd-mergeClassAttribute"><xsl:with-param name="source">2</xsl:with-param><xsl:with-param name="element" select="$elementName"/><xsl:with-param name="class" select="$className"/><xsl:with-param name="fromODD"><xsl:value-of select="$fromODD"/></xsl:with-param></xsl:call-template></xsl:for-each></attList></xsl:for-each></xsl:when><!-- d) there are changes to attributes in the class spec itself,
but the element makes no override --><xsl:when test="@mode='change' and tei:attList and not (contains($anyChanged,':element-'))"><xsl:if test="$verbose='true'"><xsl:message>Phase 1 check d) Class<xsl:value-of select="$className"/>for<xsl:value-of select="$elementName"/>has no changes in element, refer by name</xsl:message></xsl:if><attRef xmlns="http://www.tei-c.org/ns/1.0" n="5" name="{$className}.attributes"/></xsl:when><!-- e) there are changes to attributes in the class spec itself --><xsl:when test="@mode='change' and tei:attList"><!-- always references attributes in add mode --><xsl:for-each select="tei:attList/tei:attDef[@mode='add']"><attRef xmlns="http://www.tei-c.org/ns/1.0" n="2" name="{$className}.attribute.{translate(@ident,':','')}"/></xsl:for-each><!-- go back to original and proceed from there --><xsl:for-each select="document($Source)/tei:TEI"><xsl:for-each select="key('odd2odd-ATTCLASSES',$className)"><xsl:call-template name="odd2odd-tryAttributes"><xsl:with-param name="elementName" select="$elementName"/><xsl:with-param name="className" select="$className"/><xsl:with-param name="fromODD"><xsl:value-of select="$fromODD"/></xsl:with-param></xsl:call-template></xsl:for-each></xsl:for-each><xsl:for-each select="tei:attList/tei:attRef"><xsl:copy-of select="."/></xsl:for-each></xsl:when><!-- there are no changes to the attributes in the odd--><xsl:when test="$anyChanged=''"><xsl:if test="$verbose='true'"><xsl:message>Phase 1 check f) Class<xsl:value-of select="$className"/>for<xsl:value-of select="$elementName"/>has no changes, refer by name</xsl:message></xsl:if><attRef xmlns="http://www.tei-c.org/ns/1.0" n="4" name="{$className}.attributes"/></xsl:when><xsl:otherwise><xsl:if test="$verbose='true'"><xsl:message>Phase 1 check g) Class<xsl:value-of select="$className"/>for<xsl:value-of select="$elementName"/>has changes in odd, refer by values</xsl:message></xsl:if><!-- attributes here --><xsl:for-each select="tei:attList/tei:attDef"><xsl:call-template name="odd2odd-mergeClassAttribute"><xsl:with-param name="source">7</xsl:with-param><xsl:with-param name="element" select="$elementName"/><xsl:with-param name="class" select="$className"/><xsl:with-param name="fromODD"><xsl:value-of select="$fromODD"/></xsl:with-param></xsl:call-template></xsl:for-each><!-- embedded attribute lists --><xsl:for-each select="tei:attList/tei:attList"><attList xmlns="http://www.tei-c.org/ns/1.0"><xsl:copy-of select="@org"/><xsl:for-each select="tei:attDef"><xsl:call-template name="odd2odd-mergeClassAttribute"><xsl:with-param name="source">8</xsl:with-param><xsl:with-param name="element" select="$elementName"/><xsl:with-param name="class" select="$className"/><xsl:with-param name="fromODD"><xsl:value-of select="$fromODD"/></xsl:with-param></xsl:call-template></xsl:for-each></attList></xsl:for-each></xsl:otherwise></xsl:choose><!-- Now attributes referenced from classes we are a member
of. Again, check whether we are in ODD or not. If
we have not tinkered with the superclass, this is not
needed, obviously.
--><!-- DEBUG
<xsl:message>Now time to look at subclasses of <xsl:value-of
select="@ident"/> whose changes status was <xsl:value-of
select="$anyChanged"/>; we are in fromOdd <xsl:value-of
select="$fromODD"/></xsl:message>
--><xsl:choose><xsl:when test="@mode='change' and tei:attList and not (contains($anyChanged,':element-'))"/><xsl:when test="$fromODD='false' and $anyChanged =''"/><xsl:when test="$fromODD='true' and not(.//tei:attDef)"/><xsl:when test="$fromODD='true' and tei:classes[@mode='replace']"><xsl:for-each select="tei:classes/tei:memberOf"><xsl:call-template name="odd2odd-classAttributes"><xsl:with-param name="whence">3</xsl:with-param><xsl:with-param name="elementName" select="$elementName"/><xsl:with-param name="className" select="@key"/></xsl:call-template></xsl:for-each></xsl:when><xsl:otherwise><xsl:if test="$fromODD='true' and tei:classes[@mode='change']"><xsl:for-each select="tei:classes/tei:memberOf[@mode='add']"><xsl:call-template name="odd2odd-classAttributes"><xsl:with-param name="whence">4</xsl:with-param><xsl:with-param name="elementName" select="$elementName"/><xsl:with-param name="className" select="@key"/></xsl:call-template></xsl:for-each></xsl:if><xsl:for-each select="document($Source)/tei:TEI"><xsl:for-each select="key('odd2odd-ATTCLASSES',$className)"><xsl:for-each select="tei:classes/tei:memberOf"><xsl:call-template name="odd2odd-classAttributes"><xsl:with-param name="whence">5</xsl:with-param><xsl:with-param name="elementName" select="$elementName"/><xsl:with-param name="className" select="@key"/></xsl:call-template></xsl:for-each></xsl:for-each></xsl:for-each></xsl:otherwise></xsl:choose></xsl:if></xsl:template>
<xsl:template name="odd2odd-mergeClassAttribute"><!--
sitting on a source class. look at the
attribute and see whether it has changed
in the customization
--><xsl:param name="source"/><xsl:param name="element"/><xsl:param name="class"/><xsl:param name="fromODD"/><xsl:variable name="att" select="@ident"/><xsl:variable name="wherefrom" select="."/><xsl:variable name="attRef"><xsl:value-of select="concat($class,'.attribute.' ,translate($att,':',''),'_',$element)"/></xsl:variable><xsl:variable name="lookingAt"><xsl:value-of select="concat($element,'_',@ident)"/></xsl:variable><xsl:for-each select="$ODD"><xsl:choose><!-- deleted in the customization at the class level --><xsl:when test="key('odd2odd-DELETEATT',concat($class,'_',$att))"/><!-- deleted in the customization at the element level --><xsl:when test="key('odd2odd-DELETEATT',$lookingAt)"/><!-- replaced in the customization at the element level --><xsl:when test="key('odd2odd-REPLACEATT',$lookingAt)"/><!-- changed in the customization by the element --><xsl:when test="key('odd2odd-CHANGEATT',$lookingAt)"><xsl:call-template name="odd2odd-mergeAttribute"><xsl:with-param name="New" select="key('odd2odd-CHANGEATT',$lookingAt)"/><xsl:with-param name="Old" select="$wherefrom"/></xsl:call-template></xsl:when><xsl:otherwise><xsl:choose><xsl:when test="$fromODD='false'"><xsl:for-each select="$wherefrom"><xsl:call-template name="odd2odd-unChangedAtt"><xsl:with-param name="debug">1</xsl:with-param><xsl:with-param name="lookingAt"><xsl:value-of select="$lookingAt"/></xsl:with-param><xsl:with-param name="att"><xsl:value-of select="$att"/></xsl:with-param><xsl:with-param name="attRef"><xsl:value-of select="$attRef"/></xsl:with-param><xsl:with-param name="class"><xsl:value-of select="$class"/></xsl:with-param><xsl:with-param name="orig"><xsl:value-of select="$wherefrom"/></xsl:with-param></xsl:call-template></xsl:for-each></xsl:when><xsl:otherwise><xsl:call-template name="odd2odd-unChangedAtt"><xsl:with-param name="debug">2</xsl:with-param><xsl:with-param name="lookingAt"><xsl:value-of select="$lookingAt"/></xsl:with-param><xsl:with-param name="att"><xsl:value-of select="$att"/></xsl:with-param><xsl:with-param name="attRef"><xsl:value-of select="$attRef"/></xsl:with-param><xsl:with-param name="class"><xsl:value-of select="$class"/></xsl:with-param><xsl:with-param name="orig"><xsl:value-of select="$wherefrom"/></xsl:with-param></xsl:call-template></xsl:otherwise></xsl:choose></xsl:otherwise></xsl:choose></xsl:for-each></xsl:template>
<xsl:template name="odd2odd-unChangedAtt"><xsl:param name="lookingAt"/><xsl:param name="att"/><xsl:param name="class"/><xsl:param name="orig"/><xsl:param name="attRef"/><xsl:param name="debug"/><xsl:choose><!-- don't make another reference to a class attribute
if we already have an attRef --><xsl:when test="key('odd2odd-ATTREFS',$attRef)"/><xsl:otherwise><attRef xmlns="http://www.tei-c.org/ns/1.0" n="3-{$debug}" name="{$class}.attribute.{translate($att,':','')}"/></xsl:otherwise></xsl:choose></xsl:template>
<xsl:template name="odd2odd-checkClassAttribute"><xsl:param name="element"/><!-- look at each attribute in turn, and then repeat for any
inherited classes --><xsl:variable name="class" select="@ident"/><xsl:variable name="mode" select="@mode"/><xsl:for-each select="tei:attList//tei:attDef"><xsl:variable name="att" select="@ident"/><xsl:for-each select="$ODD"><xsl:choose><!-- deleted in the customization at the class level --><xsl:when test="key('odd2odd-DELETEATT',concat($class,'_',$att))"><xsl:text>:class-del-</xsl:text><xsl:value-of select="$att"/></xsl:when><!-- deleted in the customization at the element level --><xsl:when test="key('odd2odd-DELETEATT',concat($element,'_',$att))"><xsl:text>:element-del-</xsl:text><xsl:value-of select="$att"/></xsl:when><!-- replaced in the customization at the element level --><xsl:when test="key('odd2odd-REPLACEATT',concat($element,'_',$att))"><xsl:text>:element-replace-</xsl:text><xsl:value-of select="$att"/></xsl:when><!-- changed in the customization by the element --><xsl:when test="key('odd2odd-CHANGEATT',concat($element,'_',$att))"><xsl:text>:element-change-</xsl:text><xsl:value-of select="$att"/></xsl:when></xsl:choose></xsl:for-each></xsl:for-each><xsl:for-each select="tei:classes/tei:memberOf"><xsl:for-each select="key('odd2odd-ATTCLASSES',@key)"><xsl:call-template name="odd2odd-checkClassAttribute"><xsl:with-param name="element" select="$element"/></xsl:call-template></xsl:for-each></xsl:for-each></xsl:template>
<xsl:template name="odd2odd-processAttributes"><xsl:param name="ORIGINAL"/><xsl:param name="elementName"/><!-- first put in the ones we know take precedence --><xsl:apply-templates mode="odd2odd-justcopy" select="tei:attList/tei:attDef[@mode='add' or not(@mode)]"/><xsl:apply-templates mode="odd2odd-justcopy" select="tei:attList/tei:attDef[@mode='replace']"/><xsl:for-each select="$ORIGINAL/tei:attList"><!-- original source context --><xsl:for-each select="tei:attList"><attList xmlns="http://www.tei-c.org/ns/1.0"><xsl:copy-of select="@org"/><xsl:for-each select="tei:attDef"><xsl:variable name="ATT" select="."/><xsl:variable name="lookingAt"><xsl:value-of select="concat(../../../@ident,'_',@ident)"/></xsl:variable><xsl:for-each select="$ODD"><xsl:choose><xsl:when test="key('odd2odd-DELETEATT',$lookingAt)"/><xsl:when test="key('odd2odd-REPLACEATT',$lookingAt)"/><xsl:when test="key('odd2odd-CHANGEATT',$lookingAt)"><xsl:call-template name="odd2odd-mergeAttribute"><xsl:with-param name="New" select="key('odd2odd-CHANGEATT',$lookingAt)"/><xsl:with-param name="Old" select="$ATT"/></xsl:call-template></xsl:when><xsl:otherwise><xsl:copy-of select="$ATT"/></xsl:otherwise></xsl:choose></xsl:for-each></xsl:for-each></attList></xsl:for-each><xsl:variable name="atts"><xsl:for-each select="tei:attDef"><xsl:variable name="ATT" select="."/><xsl:variable name="lookingAt"><xsl:value-of select="concat(../../@ident,'_',@ident)"/></xsl:variable><xsl:for-each select="$ODD"><xsl:choose><xsl:when test="key('odd2odd-DELETEATT',$lookingAt)"/><xsl:when test="key('odd2odd-REPLACEATT',$lookingAt)"/><xsl:when test="key('odd2odd-CHANGEATT',$lookingAt)"><xsl:call-template name="odd2odd-mergeAttribute"><xsl:with-param name="New" select="key('odd2odd-CHANGEATT',$lookingAt)"/><xsl:with-param name="Old" select="$ATT"/></xsl:call-template></xsl:when><xsl:otherwise><xsl:copy-of select="$ATT"/></xsl:otherwise></xsl:choose></xsl:for-each></xsl:for-each></xsl:variable><xsl:choose><xsl:when test="@org"><attList xmlns="http://www.tei-c.org/ns/1.0"><xsl:copy-of select="@org"/><xsl:copy-of select="$atts"/></attList></xsl:when><xsl:otherwise><xsl:copy-of select="$atts"/></xsl:otherwise></xsl:choose></xsl:for-each><!-- now we need to go back to the classes of which this
element is a member and reference their untouched attributes --><xsl:choose><xsl:when test="$elementName=''"/><xsl:otherwise><xsl:if test="$autoGlobal='true'"><xsl:call-template name="odd2odd-classAttributes"><xsl:with-param name="whence">7</xsl:with-param><xsl:with-param name="elementName" select="$elementName"/><xsl:with-param name="className" select="'att.global'"/></xsl:call-template></xsl:if><xsl:variable name="classMembership"><x><xsl:choose><xsl:when test="tei:classes[@mode='change']"><xsl:for-each select="tei:classes/tei:memberOf[not(@mode='delete')]"><xsl:copy-of select="."/></xsl:for-each><xsl:for-each select="$ORIGINAL"><xsl:for-each select="tei:classes/tei:memberOf"><xsl:copy-of select="."/></xsl:for-each></xsl:for-each></xsl:when><xsl:when test="tei:classes"><xsl:for-each select="tei:classes/tei:memberOf"><xsl:copy-of select="."/></xsl:for-each></xsl:when><xsl:otherwise><xsl:for-each select="$ORIGINAL"><xsl:for-each select="tei:classes/tei:memberOf"><xsl:copy-of select="."/></xsl:for-each></xsl:for-each></xsl:otherwise></xsl:choose></x></xsl:variable><xsl:for-each select="$classMembership/x/tei:memberOf"><xsl:if test="not(preceding-sibling::tei:memberOf[@key=current()/@key])"><xsl:call-template name="odd2odd-classAttributes"><xsl:with-param name="whence">8</xsl:with-param><xsl:with-param name="elementName" select="$elementName"/><xsl:with-param name="className" select="@key"/></xsl:call-template></xsl:if></xsl:for-each></xsl:otherwise></xsl:choose></xsl:template>
<xsl:template name="odd2odd-processConstraints"><xsl:param name="ORIGINAL"/><xsl:param name="elementName"/><!-- first put in the ones we know take precedence --><xsl:apply-templates mode="odd2odd-justcopy" select="tei:constraintSpec[@mode='add' or not(@mode)]"/><xsl:apply-templates mode="odd2odd-justcopy" select="tei:constraintSpec[@mode='replace']"/><xsl:apply-templates mode="odd2odd-justcopy" select="tei:constraintSpec[@mode='change']"/><xsl:for-each select="$ORIGINAL"><!-- original source context --><xsl:for-each select="tei:constraintSpec"><xsl:variable name="CONSTRAINT" select="."/><xsl:variable name="lookingAt"><xsl:value-of select="concat(../@ident,'_',@ident)"/></xsl:variable><xsl:for-each select="$ODD"><xsl:choose><xsl:when test="key('odd2odd-DELETECONSTRAINT',$lookingAt)"/><xsl:when test="key('odd2odd-REPLACECONSTRAINT',$lookingAt)"/><xsl:when test="key('odd2odd-CHANGECONSTRAINT',$lookingAt)"/><xsl:otherwise><xsl:copy-of select="$CONSTRAINT"/></xsl:otherwise></xsl:choose></xsl:for-each></xsl:for-each></xsl:for-each></xsl:template>