TEI stylesheet for merging TEI ODD specification with source to
make a new source document.
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
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="tei:schemaSpec" mode="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="pass0"/></xsl:copy></xsl:if></xsl:template>
<xsl:template match="tei:schemaSpec" mode="pass1"><xsl:variable name="pass1"><xsl:copy><xsl:copy-of select="@*"/><xsl:sequence select="if ($verbose='true')then tei:message(concat('Schema pass 1: ',@ident)) else ()"/><!--
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:for-each><xsl:for-each select="tei:moduleRef[@key='core']"><xsl:call-template name="odd2odd-expandModule"/></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:if></xsl:for-each><xsl:for-each select="*[not(self::tei:moduleRef[@key])]"><xsl:apply-templates select="." mode="pass1"/></xsl:for-each></xsl:copy></xsl:variable><!--
<xsl:result-document href="/tmp/odd2odd-pass1.xml">
<xsl:copy-of select="$pass1"/>
</xsl:result-document>
--><xsl:for-each select="$pass1"><xsl:apply-templates mode="pass2"/></xsl:for-each></xsl:template>
<xsl:template match="tei:classSpec[@mode='add' or (not(@mode) and ancestor::tei:schemaSpec)]" mode="pass1"><xsl:call-template name="odd2odd-createCopy"/></xsl:template>
<xsl:template match="tei:macroSpec[@mode='add' or (not(@mode) and ancestor::tei:schemaSpec)]" mode="pass1"><xsl:call-template name="odd2odd-createCopy"/></xsl:template>
<xsl:template match="tei:elementSpec[@mode='add' or (not(@mode) and ancestor::tei:schemaSpec)]" mode="pass1"><xsl:call-template name="odd2odd-createCopy"/></xsl:template>
<xsl:template name="odd2odd-checkObject"><!--
for every object
- if its in the ODD spec's REPLACE list, use that
- if its in ODD spec's CHANGE list (do the hard merge bit)
- if its duplicated by an existing spec, ignore
- otherwise copy
done
--><xsl:variable name="specName" select="tei:uniqueName(.)"/><xsl:variable name="N" select="local-name(.)"/><xsl:choose><xsl:when test="$ODD/key('odd2odd-DELETE',$specName)"><xsl:if test="$verbose='true'"><xsl:message>Phase 2: delete<xsl:value-of select="$specName"/></xsl:message></xsl:if></xsl:when><xsl:when test="$ODD/key('odd2odd-REPLACE',$specName)"><xsl:if test="$verbose='true'"><xsl:message>Phase 2: replace<xsl:value-of select="$specName"/></xsl:message></xsl:if><xsl:apply-templates mode="odd2odd-copy" select="$ODD/key('odd2odd-REPLACE',$specName)"/></xsl:when><xsl:when test="$ODD/key('odd2odd-CHANGE',$specName)"><xsl:if test="$verbose='true'"><xsl:message>Phase 2: change<xsl:value-of select="$specName"/></xsl:message></xsl:if><xsl:apply-templates mode="odd2odd-change" select="."/></xsl:when><xsl:otherwise><xsl:if test="$verbose='true'"><xsl:message>Phase 2: keep<xsl:value-of select="$specName"/></xsl:message></xsl:if><xsl:apply-templates mode="justcopy" select="."/></xsl:otherwise></xsl:choose></xsl:template>
<xsl:template match="tei:elementSpec" mode="odd2odd-change"><xsl:variable name="elementName" select="tei:uniqueName(.)"/><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/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="justcopy" select="tei:altIdent"/><!-- equiv, gloss, desc trio --><xsl:choose><xsl:when test="tei:equiv"><xsl:apply-templates mode="justcopy" select="tei:equiv"><xsl:with-param name="rend">replace</xsl:with-param></xsl:apply-templates></xsl:when><xsl:otherwise><xsl:apply-templates mode="justcopy" select="$ORIGINAL/tei:equiv"/></xsl:otherwise></xsl:choose><xsl:choose><xsl:when test="tei:gloss"><xsl:apply-templates mode="justcopy" select="tei:gloss"><xsl:with-param name="rend">replace</xsl:with-param></xsl:apply-templates></xsl:when><xsl:otherwise><xsl:apply-templates mode="justcopy" select="$ORIGINAL/tei:gloss"/></xsl:otherwise></xsl:choose><xsl:choose><xsl:when test="$stripped='true'"/><xsl:when test="tei:desc"><xsl:apply-templates mode="justcopy" select="tei:desc"><xsl:with-param name="rend">replace</xsl:with-param></xsl:apply-templates></xsl:when><xsl:otherwise><xsl:apply-templates mode="justcopy" select="$ORIGINAL/tei:desc"/></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:choose><xsl:when test="$ODD/key('odd2odd-DELETE',$me)"></xsl:when><xsl:when test="$ODD/key('odd2odd-MEMBEROFDELETE',$metoo)"></xsl:when><xsl:when test="$ODD/key('odd2odd-MEMBEROFADD',$metoo)"></xsl:when><xsl:otherwise><memberOf key="{$me}"/></xsl:otherwise></xsl:choose></xsl:for-each></xsl:for-each></xsl:when><xsl:when test="tei:classes"><xsl:for-each select="tei:classes/tei:memberOf[not(@mode='delete')]"><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:apply-templates mode="odd2odd-copy" select="$ORIGINAL/tei:valList"/></xsl:otherwise></xsl:choose><!-- element content --><content xmlns="http://www.tei-c.org/ns/1.0"><xsl:choose><xsl:when test="tei:content and not(tei:content/*)"/><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:apply-templates mode="odd2odd-copy" select="tei:content/*"/></xsl:when><xsl:otherwise><xsl:apply-templates mode="odd2odd-copy" select="$ORIGINAL/tei:content/@*"/><xsl:apply-templates mode="odd2odd-copy" select="$ORIGINAL/tei:content/*"/></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="justcopy" select="tei:attList/@org"/><xsl:call-template name="odd2odd-processAttributes"><xsl:with-param name="ORIGINAL" select="$ORIGINAL"/><xsl:with-param name="objectName" 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="justcopy" select="tei:exemplum"/></xsl:when><xsl:otherwise><xsl:apply-templates mode="justcopy" select="$ORIGINAL/tei:exemplum"/></xsl:otherwise></xsl:choose><xsl:choose><xsl:when test="$stripped='true'"/><xsl:when test="tei:remarks"><xsl:apply-templates mode="justcopy" select="tei:remarks"/></xsl:when><xsl:otherwise><xsl:apply-templates mode="justcopy" select="$ORIGINAL/tei:remarks"/></xsl:otherwise></xsl:choose><xsl:choose><xsl:when test="tei:listRef"><xsl:apply-templates mode="justcopy" select="tei:listRef"/></xsl:when><xsl:otherwise><xsl:apply-templates mode="justcopy" select="$ORIGINAL/tei:listRef"/></xsl:otherwise></xsl:choose></xsl:for-each></xsl:copy></xsl:template>
<xsl:template match="tei:macroSpec" mode="odd2odd-change"><xsl:variable name="specName" select="tei:uniqueName(.)"/><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',$specName)"><!-- if there is an altIdent, use it --><xsl:apply-templates mode="justcopy" select="tei:altIdent"/><!-- equiv, gloss, desc trio --><xsl:choose><xsl:when test="$stripped='true'"/><xsl:when test="tei:equiv"><xsl:apply-templates mode="justcopy" select="tei:equiv"><xsl:with-param name="rend">replace</xsl:with-param></xsl:apply-templates></xsl:when><xsl:otherwise><xsl:apply-templates mode="odd2odd-copy" select="$ORIGINAL/tei:equiv"/></xsl:otherwise></xsl:choose><xsl:choose><xsl:when test="tei:gloss"><xsl:apply-templates mode="justcopy" select="tei:gloss"><xsl:with-param name="rend">replace</xsl:with-param></xsl:apply-templates></xsl:when><xsl:otherwise><xsl:apply-templates mode="justcopy" select="$ORIGINAL/tei:gloss"/></xsl:otherwise></xsl:choose><xsl:choose><xsl:when test="$stripped='true'"/><xsl:when test="tei:desc"><xsl:apply-templates mode="justcopy" select="tei:desc"><xsl:with-param name="rend">replace</xsl:with-param></xsl:apply-templates></xsl:when><xsl:otherwise><xsl:apply-templates mode="justcopy" select="$ORIGINAL/tei:desc"/></xsl:otherwise></xsl:choose><!-- content --><xsl:choose><xsl:when test="tei:content"><xsl:apply-templates mode="justcopy" select="tei:content"><xsl:with-param name="rend">replace</xsl:with-param></xsl:apply-templates></xsl:when><xsl:otherwise><xsl:apply-templates mode="odd2odd-copy" select="$ORIGINAL/tei:content"/></xsl:otherwise></xsl:choose><xsl:choose><xsl:when test="tei:valList"><xsl:apply-templates mode="justcopy" select="tei:valList[1]"><xsl:with-param name="rend">replace</xsl:with-param></xsl:apply-templates></xsl:when><xsl:when test="tei:stringVal"><xsl:apply-templates mode="justcopy" select="tei:stringVal"/></xsl:when><xsl:otherwise><xsl:apply-templates mode="odd2odd-copy" select="$ORIGINAL/tei:stringVal"/></xsl:otherwise></xsl:choose><!-- constraints --><xsl:call-template name="odd2odd-processConstraints"><xsl:with-param name="ORIGINAL" select="$ORIGINAL"/><xsl:with-param name="elementName" select="$specName"/></xsl:call-template><!-- 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="justcopy" select="tei:exemplum"/></xsl:when><xsl:otherwise><xsl:apply-templates mode="justcopy" select="$ORIGINAL/tei:exemplum"/></xsl:otherwise></xsl:choose><xsl:choose><xsl:when test="tei:remarks"><xsl:apply-templates mode="justcopy" select="tei:remarks"/></xsl:when><xsl:otherwise><xsl:apply-templates mode="justcopy" select="$ORIGINAL/tei:remarks"/></xsl:otherwise></xsl:choose><xsl:choose><xsl:when test="$stripped='true'"/><xsl:when test="tei:listRef"><xsl:apply-templates mode="justcopy" select="tei:listRef"/></xsl:when><xsl:otherwise><xsl:apply-templates mode="justcopy" select="$ORIGINAL/tei:listRef"/></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" select="tei:uniqueName(.)"/><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="justcopy" select="tei:desc"/></xsl:when><xsl:otherwise><xsl:apply-templates mode="justcopy" select="$ORIGINAL/tei:desc"/></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:choose><xsl:when test="$ODD/key('odd2odd-DELETE',$me)"></xsl:when><xsl:when test="$ODD/key('odd2odd-MEMBEROFDELETE',$metoo)"></xsl:when><xsl:when test="$ODD/key('odd2odd-MEMBEROFADD',$metoo)"></xsl:when><xsl:otherwise><memberOf key="{$me}"/></xsl:otherwise></xsl:choose></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><!-- constraints --><xsl:call-template name="odd2odd-processConstraints"><xsl:with-param name="ORIGINAL" select="$ORIGINAL"/><xsl:with-param name="elementName" select="$className"/></xsl:call-template><!-- 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="objectName" select="$className"/></xsl:call-template></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:value-of select="count($contents/WHAT/*)"/></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-processAttributes"><xsl:param name="ORIGINAL"/><xsl:param name="objectName"/><!-- we are sitting in the ODD --><!-- first put in the ones we know take precedence as replacements --><xsl:for-each select="tei:attList/tei:attDef[@mode='replace' and @ident=$ORIGINAL/tei:attList//tei:attDef/@ident]"><attDef xmlns="http://www.tei-c.org/ns/1.0"><xsl:apply-templates select="@*"/><xsl:apply-templates mode="justcopy"/></attDef></xsl:for-each><xsl:for-each select="tei:attList/tei:attDef[@mode='add' or not(@mode)]"><attDef xmlns="http://www.tei-c.org/ns/1.0"><xsl:apply-templates select="@*[not(name()='mode')]"/><xsl:apply-templates mode="justcopy"/></attDef></xsl:for-each><!-- class attributes are ones where there is no direct correspondence in
the source for this element --><xsl:apply-templates mode="justcopy" select="tei:attList/tei:attDef[(@mode='change' or @mode='delete' or @mode='replace') and not(@ident=$ORIGINAL/tei:attList//tei:attDef/@ident)]"/><!-- any direct attRef elements --><xsl:apply-templates mode="justcopy" select="tei:attList/tei:attRef"/><!-- now look at each of the original object's attributes and see
if we have an update --><xsl:for-each select="$ORIGINAL/tei:attList"><!-- original source context --><!-- first looking at nested attList --><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:choose><xsl:when test="ancestor::tei:classSpec and $ODD/key('odd2odd-DELETEATT',$lookingAt)"/><xsl:when test="$ODD/key('odd2odd-DELETEATT',$lookingAt)"><xsl:copy-of select="$ODD/key('odd2odd-DELETEATT',$lookingAt)"/></xsl:when><xsl:when test="$ODD/key('odd2odd-REPLACEATT',$lookingAt)"/><xsl:when test="$ODD/key('odd2odd-CHANGEATT',$lookingAt)"><xsl:call-template name="odd2odd-mergeAttribute"><xsl:with-param name="New" select="$ODD/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></attList></xsl:for-each><!-- now the normal attributes --><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:choose><xsl:when test="ancestor::tei:classSpec and $ODD/key('odd2odd-DELETEATT',$lookingAt)"/><xsl:when test="$ODD/key('odd2odd-DELETEATT',$lookingAt)"><xsl:copy-of select="$ODD/key('odd2odd-DELETEATT',$lookingAt)"/></xsl:when><xsl:when test="$ODD/key('odd2odd-REPLACEATT',$lookingAt)"/><xsl:when test="$ODD/key('odd2odd-CHANGEATT',$lookingAt)"><xsl:call-template name="odd2odd-mergeAttribute"><xsl:with-param name="New" select="$ODD/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: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></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="justcopy" select="tei:constraintSpec[@mode='add' or not(@mode)]"/><xsl:apply-templates mode="justcopy" select="tei:constraintSpec[@mode='replace']"/><xsl:apply-templates mode="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>
<xsl:template name="odd2odd-amINeeded"><!--
How can a class be ok?
a) if an element is a member of it and
b) its referred to in a content model
c) some other class is a member of it, and that class is OK
d) its a member of some other class, 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="@type='model' and key('odd2odd-REFED',$k)">y</xsl:when><xsl:when test="@type='atts' and key('odd2odd-ATTREFED',$k)">y</xsl:when><xsl:when test="@type='atts' and key('odd2odd-ELEMENT_MEMBERED',$k)">y</xsl:when><xsl:when test="@type='atts' and 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:when test="@type='model' and tei:classes/tei:memberOf"><xsl:for-each select="tei:classes/tei:memberOf/key('odd2odd-IDENTS',@key)"><xsl:call-template name="odd2odd-amINeeded"/></xsl:for-each></xsl:when></xsl:choose></xsl:template>
<xsl:function name="tei:uniqueName" as="xs:string"><xsl:param name="e"/><xsl:for-each select="$e"><xsl:sequence select="concat( if (@ns='http://www.tei-c.org/ns/1.0') then '' else if (@ns) then @ns else if (ancestor::tei:schemaSpec/@ns) then ancestor::tei:schemaSpec/@ns else '',@ident)"/></xsl:for-each></xsl:function>