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="processing-instruction()" mode="#default tangle"><xsl:choose><xsl:when test="name(.) = 'odds'"><xsl:choose><xsl:when test=".='date'">This formatted version of the Guidelines was created on<xsl:sequence select="tei:whatsTheDate()"/>.</xsl:when></xsl:choose></xsl:when><xsl:otherwise><xsl:copy-of select="."/></xsl:otherwise></xsl:choose></xsl:template>
<xsl:template match="rng:group" mode="#default tangle"><!-- check if this group is identical to the last --><xsl:choose><xsl:when test="count(rng:*)=1 and local-name(preceding-sibling::rng:*[1])='group' and rng:zeroOrMore"><xsl:variable name="that"><xsl:for-each select="preceding-sibling::rng:*[1]"><xsl:apply-templates mode="decomposed"/></xsl:for-each></xsl:variable><xsl:variable name="this"><xsl:apply-templates mode="decomposed"/></xsl:variable><xsl:choose><xsl:when test="$that=$this"/><xsl:otherwise><rng:group><xsl:copy-of select="@*"/><xsl:apply-templates select="rng:*|tei:*|text()|comment()"/></rng:group></xsl:otherwise></xsl:choose></xsl:when><xsl:otherwise><xsl:element name="{local-name()}" namespace="http://relaxng.org/ns/structure/1.0"><xsl:copy-of select="@*"/><xsl:apply-templates select="rng:*|tei:*|text()|comment()"/></xsl:element></xsl:otherwise></xsl:choose></xsl:template>
Given an element (presumably a RELAX NG element), generate the
correct RELAX NG code around that element to match it the right
number of times based on the @minOccurs and @maxOccurs of the
current context node (which is presumably a member of
att.repeatable).
<xsl:template name="repeat_as_needed" as="element()+"><xsl:param name="repeatMe" as="element()+"/><xsl:variable name="norMinMax" select="tei:norMinMax(.)" as="item()+"/><xsl:variable name="min" select="$norMinMax[1]"/><!-- minimum number of occurrences as an xs:integer --><xsl:variable name="max" select="$norMinMax[2]"/><!-- maximum number of occurrences as an xs:integer, -1 for unbounded --><xsl:variable name="owe" select="$norMinMax[3]"/><!-- occurrence wrapper element, as the string "optional", "zeroOrMore", or "oneOrMore" --><xsl:choose><!-- Handle min=0 max=1, min=0 max=unbounded, and min=1 max=unbounded all in one fell swoop: --><xsl:when test="string-length($owe) ne 0"><xsl:element name="{$owe}" namespace="http://relaxng.org/ns/structure/1.0"><xsl:copy-of select="$repeatMe"/></xsl:element></xsl:when><xsl:otherwise><!-- a more complex case --><xsl:if test="$min gt 0"><xsl:for-each select="1 to $min"><xsl:copy-of select="$repeatMe"/></xsl:for-each></xsl:if><xsl:choose><xsl:when test="$max eq -1"><!-- i.e., unbounded --><rng:zeroOrMore><xsl:copy-of select="$repeatMe"/></rng:zeroOrMore></xsl:when><xsl:otherwise><xsl:for-each select="$min+1 to $max"><rng:optional><xsl:copy-of select="$repeatMe"/></rng:optional></xsl:for-each></xsl:otherwise></xsl:choose></xsl:otherwise></xsl:choose></xsl:template>
<xsl:template match="tei:attDef" mode="tangle"><xsl:param name="element"/><!-- This tunneled parameters is set when we are processing
attDefs in the context of generating documentation of an
element content model, so that we
don't spew out Schematron in the middle of it. --><xsl:param tunnel="yes" as="xs:boolean" name="includeConstraints" select="true()"/><xsl:variable name="I"><xsl:value-of select="translate(@ident,':','')"/></xsl:variable><xsl:if test="not(starts-with(@ident,'xmlns'))"><xsl:choose><xsl:when test="ancestor::tei:elementSpec"><xsl:call-template name="makeAnAttribute"/></xsl:when><xsl:when test="ancestor::tei:classSpec"><rng:define name="{$element}.attribute.{translate(@ident,':','')}"><xsl:call-template name="makeAnAttribute"/></rng:define></xsl:when></xsl:choose></xsl:if><xsl:if test="$includeConstraints = true()"><xsl:apply-templates select="tei:constraintSpec"/></xsl:if></xsl:template>
<xsl:template match="tei:dataRef" mode="#default tangle"><xsl:choose><xsl:when test="@name"><rng:data type="{@name}"><xsl:if test="@restriction"><rng:param name="pattern"><xsl:value-of select="@restriction"/></rng:param></xsl:if></rng:data></xsl:when><xsl:when test="@key"><rng:ref name="{@key}"/></xsl:when><!-- this routine does not process @ref, not sure why not (also not sure --><!-- how we would do that, so maybe that's why not :-) —Syd, 2016-11-25 --></xsl:choose></xsl:template>
<xsl:template match="tei:moduleRef" mode="tangle"><!-- save a reference to myself so I can access my attrs and --><!-- generated node ID later --><xsl:variable name="me-the-moduleRef" select="."/><xsl:variable name="This" select="@key"/><xsl:if test="$verbose='true'"><xsl:message>.... import module [<xsl:value-of select="$This"/><xsl:value-of select="@url"/>]</xsl:message></xsl:if><xsl:call-template name="schemaOut"><xsl:with-param name="grammar">true</xsl:with-param><xsl:with-param name="content"><Wrapper><xsl:choose><xsl:when test="@url and $parameterize='true'"><rng:include href="{@url}"><xsl:apply-templates mode="justcopy" select="tei:content/*"/></rng:include></xsl:when><xsl:when test="@url and $parameterize='false'"><xsl:comment>Start of import of <xsl:value-of select="@url"/></xsl:comment><rng:div><xsl:choose><xsl:when test="doc-available(resolve-uri(@url,$BASE))"><xsl:for-each select="doc(resolve-uri(@url,$BASE))/rng:grammar"><!-- the "expandRNG" processing changed 2011-08-25 by Syd Bauman: --><!-- added a 'prefix' parameter which value is prefixed to pattern --><!-- names in the included schema. This prevents collisions in the --><!-- output RNG. --><xsl:apply-templates mode="expandRNG" select="@*|node()"><xsl:with-param name="prefix"><xsl:if test="$me-the-moduleRef/@prefix"><xsl:value-of select="$me-the-moduleRef/@prefix"/></xsl:if></xsl:with-param></xsl:apply-templates></xsl:for-each></xsl:when><xsl:otherwise><xsl:message terminate="yes"><xsl:text>Document not available: </xsl:text><xsl:value-of select="@url"/></xsl:message></xsl:otherwise></xsl:choose><xsl:apply-templates mode="justcopy" select="tei:content/*"/></rng:div><xsl:comment>End of import of <xsl:value-of select="@url"/></xsl:comment></xsl:when><xsl:otherwise><rng:include href="{$schemaBaseURL}{$This}.rng"><xsl:attribute name="ns"><xsl:choose><xsl:when test="ancestor::tei:schemaSpec/@ns"><xsl:value-of select="ancestor::tei:schemaSpec/@ns"/></xsl:when><xsl:otherwise>http://www.tei-c.org/ns/1.0</xsl:otherwise></xsl:choose></xsl:attribute><xsl:for-each select="../tei:*[@module=$This and not(@mode='add')]"><xsl:apply-templates mode="tangle" select="."/></xsl:for-each></rng:include></xsl:otherwise></xsl:choose></Wrapper></xsl:with-param></xsl:call-template></xsl:template>
<xsl:template match="rng:define | rng:ref" mode="expandRNG"><xsl:param name="prefix"/><xsl:if test="$verbose='true'"><xsl:message>expanding rng:<xsl:value-of select="local-name(.)"/>name=<xsl:value-of select="@name"/>, giving it a prefix of '<xsl:value-of select="$prefix"/>'.</xsl:message></xsl:if><!-- generate a copy of this <define> or <ref> --><xsl:copy><!-- copy over all attributes (including @name) --><xsl:apply-templates select="@*" mode="expandRNG"/><xsl:if test="@name"><!-- then replace the copied @name with our own that is the same --><!-- except has our prefix in the value --><xsl:attribute name="name" select="concat( $prefix, @name )"/></xsl:if><!-- then copy over any content --><xsl:apply-templates select="node()" mode="expandRNG"><xsl:with-param name="prefix" select="$prefix"/></xsl:apply-templates></xsl:copy></xsl:template>
<xsl:template name="makeSimpleAttribute"><xsl:variable name="name"><xsl:choose><xsl:when test="tei:altIdent=@ident"><xsl:value-of select="@ident"/></xsl:when><xsl:when test="tei:altIdent"><xsl:value-of select="normalize-space(tei:altIdent)"/></xsl:when><xsl:otherwise><xsl:if test="@ns='http://www.w3.org/XML/1998/namespace'">xml:</xsl:if><xsl:value-of select="@ident"/></xsl:otherwise></xsl:choose></xsl:variable><rng:attribute name="{$name}"><xsl:if test="@ns"><xsl:copy-of select="@ns"/></xsl:if><xsl:if test="tei:defaultVal and not(tei:defaultVal='')"><xsl:attribute name="a:defaultValue"><xsl:value-of select="normalize-space(tei:defaultVal)"/></xsl:attribute></xsl:if><xsl:if test="not($oddmode='tei')"><a:documentation><xsl:sequence select="tei:makeDescription(., true(), true())"/></a:documentation></xsl:if><xsl:variable name="norMinMax" as="item()+" select="if (tei:datatype) then tei:norMinMax(tei:datatype) else ( 1, 1, '', '' )"/><xsl:variable name="min" select="$norMinMax[1]"/><xsl:variable name="max" select="$norMinMax[2]"/><xsl:choose><xsl:when test="$min eq 0 and $max eq 1"><rng:optional><xsl:call-template name="attributeData"/></rng:optional></xsl:when><xsl:when test="tei:datatype/rng:text or not( tei:datatype ) or $max eq 1"><!-- If there is only going to be one output RELAX NG node --><!-- in the attribute definition, then we don't need to --><!-- bother with the complex min & max code below (in the --><!-- <xsl:otherwise>). Although it would generate the right --><!-- number of RELAX NG constructs, it wraps them in a --><!-- <list>, which makes no sense in some cases, and will --><!-- cause an error if the RELAX NG node inside the list is --><!-- <text>. --><!-- Cases we handle here: --><!-- * my <datatype> child has an <rng:text> child: only 1 --><!-- output node (<rng:text>), which can't be wrapped in --><!-- a <list> --><!-- * I don't have a <datatype> child: the 'attributeData' --><!-- template will spit out a single <rng:text> node (see --><!-- the outermost <xsl:otherwise> of that template) --><!-- * @maxOccurs=1: whatever ends up being generated, there --><!-- will only be 1 of them, so no need for a <list> --><xsl:call-template name="attributeData"/></xsl:when><xsl:otherwise><!-- Note that in the (erroneous) event --><!-- that minOccurs= is greater than --><!-- maxOccurs=, the latter is simply --><!-- ignored. --><!-- Hack(?): --><!-- The 'attributeData' template needs to operate from this node; --><!-- However, once we've used for-each to "loop", we've lost the --><!-- current node (it has become one of the integers in the select= --><!-- range). So here we remember the current node, and re-set it --><!-- before calling 'attributeData'. Perhaps it would be better to --><!-- send it as a parameter to 'attributeData' and have it set the --><!-- current node, but since I didn't write 'attributeData', I've --><!-- chosen this method so I don't have to muck with it. —Syd --><xsl:variable name="thisNode" select="."/><rng:list><xsl:choose><xsl:when test="$max eq -1 (: i.e., unbounded :) and $min eq 1"><rng:oneOrMore><xsl:for-each select="$thisNode"><xsl:call-template name="attributeData"/></xsl:for-each></rng:oneOrMore></xsl:when><xsl:otherwise><xsl:if test="$min gt 0"><xsl:for-each select="1 to $min"><xsl:for-each select="$thisNode"><xsl:call-template name="attributeData"/></xsl:for-each></xsl:for-each></xsl:if><xsl:choose><xsl:when test="$max eq -1"><!-- i.e., unbounded --><rng:zeroOrMore><xsl:for-each select="$thisNode"><xsl:call-template name="attributeData"/></xsl:for-each></rng:zeroOrMore></xsl:when><xsl:otherwise><xsl:for-each select="$min+1 to $max"><rng:optional><xsl:for-each select="$thisNode"><xsl:call-template name="attributeData"/></xsl:for-each></rng:optional></xsl:for-each></xsl:otherwise></xsl:choose></xsl:otherwise></xsl:choose></rng:list></xsl:otherwise></xsl:choose></rng:attribute></xsl:template>
<xsl:template name="linkTogether"><xsl:param name="name"/><xsl:param name="reftext"/><xsl:param name="class">link_odd</xsl:param><xsl:variable name="partialname"><xsl:value-of select="replace($name,'_(alternation|sequenceOptionalRepeatable|sequenceOptional|sequenceRepeatable|sequence)','')"/></xsl:variable><xsl:variable name="link"><xsl:choose><xsl:when test="$reftext=''"><xsl:value-of select="$name"/></xsl:when><xsl:otherwise><xsl:value-of select="$reftext"/></xsl:otherwise></xsl:choose></xsl:variable><xsl:variable name="glossAndDesc"><!-- This variable will hold the string value of the <gloss> and --><!-- <desc> of the construct we are currently dealing with, in --><!-- the language we are currently dealing with, so as to put it --><!-- on the title= attribute when we output its name in an <a>. --><xsl:choose><xsl:when test="starts-with( $partialname, 'model.')"><xsl:apply-templates select="key('CLASSES', $partialname)" mode="glossDesc"/></xsl:when><xsl:when test="starts-with( $partialname, 'att.')"><xsl:apply-templates select="key('CLASSES', replace( $partialname, '\.attributes$',''))" mode="glossDesc"/></xsl:when><xsl:otherwise><xsl:apply-templates select="key('ELEMENTS', $partialname )" mode="glossDesc"/></xsl:otherwise></xsl:choose></xsl:variable><xsl:choose><xsl:when test="not(key('IDENTS',$partialname))"><xsl:value-of select="$link"/></xsl:when><xsl:when test="$oddmode='html' and number($splitLevel)=-1"><a xmlns="http://www.w3.org/1999/xhtml" class="{$class}" href="#{$partialname}"><xsl:value-of select="$link"/></a></xsl:when><xsl:when test="$oddmode='html' and $STDOUT='true'"><a xmlns="http://www.w3.org/1999/xhtml" class="{$class}"><xsl:attribute name="href"><xsl:for-each select="key('IDENTS',$partialname)"><xsl:call-template name="getSpecURL"><xsl:with-param name="name"><xsl:value-of select="$partialname"/></xsl:with-param><xsl:with-param name="type"><xsl:value-of select="substring-before(local-name(),'Spec')"/></xsl:with-param></xsl:call-template></xsl:for-each></xsl:attribute><xsl:value-of select="$link"/></a></xsl:when><xsl:when test="$oddmode='html'"><a xmlns="http://www.w3.org/1999/xhtml" class="{$class}" title="{$glossAndDesc}" href="{concat('ref-',$partialname,'.html')}"><xsl:value-of select="$link"/></a></xsl:when><xsl:when test="$oddmode='pdf'"><fo:inline><xsl:value-of select="$link"/></fo:inline></xsl:when><xsl:when test="$oddmode='tei'"><tei:ref target="#{$partialname}"><xsl:value-of select="$link"/></tei:ref></xsl:when><xsl:otherwise><xsl:value-of select="$link"/></xsl:otherwise></xsl:choose></xsl:template>
<xsl:template name="makeTEIVersion"><xsl:choose><xsl:when test="ancestor-or-self::tei:TEI/processing-instruction()[name() eq 'TEIVERSION']"><!-- JC Additions to form proper URL from version number --><!-- MH and SB: Note that this PI is created during odd2odd.xsl, and used to store version
information from p5subset.xml. --><!-- SB modified 2023-05-01 —
* Simplify code
* Correctly extract only the version number itself per ticket #607
- Note that we need to be prepared for both "P5 Version …" and just "Version …"
* Normalize space of “TEI Edition” output so it is all on one line
--><xsl:variable name="TEIVersion" select="ancestor-or-self::tei:TEI/processing-instruction()[name() eq 'TEIVERSION'][1]"/><xsl:variable name="TEIVersion-edition" select="substring-before( $TEIVersion, ' Last')"/><xsl:variable name="TEIVersion-datestring" select="concat(' Last', substring-after( $TEIVersion, ' Last') )"/><xsl:variable name="TEIVersion-only" select="replace( $TEIVersion-edition, '^(P5 )?Version (\d+\.\d+\.\d+[abABɑΑΒβ]?)\.$', '$2')"/><xsl:variable name="versionURL" select="concat( $defaultTEIServer, $TEIVersion-only, '/')"/><xsl:sequence select="'
TEI Edition: '||normalize-space($TEIVersion)"/><xsl:sequence select="'
TEI Edition Location: '||$versionURL"/><xsl:text></xsl:text></xsl:when><xsl:when test="ancestor-or-self::tei:TEI/tei:teiHeader/tei:fileDesc/tei:editionStmt/tei:edition"><xsl:text>
Edition: </xsl:text><xsl:value-of select="ancestor-or-self::tei:TEI/tei:teiHeader/tei:fileDesc/tei:editionStmt/tei:edition"/><xsl:text></xsl:text></xsl:when></xsl:choose></xsl:template>
process <gloss> and <desc> to make title= attribute values
Namespace
No namespace
Match
tei:gloss
Mode
glossDescTitle
Import precedence
0
Source
<xsl:template match="tei:gloss" mode="glossDescTitle"><!-- At the moment the only descendants of a <gloss> that appears in <elementSpec> or <classSpec> --><!-- are 3 <gloss> and 1 <ident>, so we can get away with just taking the value, rather than --><!-- applying templates. --><xsl:value-of select="normalize-space(.)"/></xsl:template>
<xsl:template match="tei:desc" mode="glossDescTitle"><!--
As of 2014-08-12, revision 12970, the only descendants of a
<desc> that appears in an <elementSpec> or a <classSpec> are:
329 gi
79 term
68 att
11 soCalled
6 mentioned
5 ident
2 q
2 val
1 foreign
1 ref
1 title
You might think that from here we can just <apply-templates>
and be done with it. But if we do that, we end up with an infinite-
loop of called templates problem. To wit, inside the <desc> we are
processing there are (e.g.) <gi> elements. They get caught by a
template in html/html_oddprocessing.xsl, which goes about calling
linkTogether, which goes about applying templates (in mode glossDesc)
to the <elementSpec> that defines the element mentioned in the content
of the <gi>. That, in turn, would apply templates to the <desc> that
we started with.
--><xsl:apply-templates mode="#current"/></xsl:template>
<xsl:template name="processSchematron"><xsl:choose><xsl:when test="self::sch:ns | self::sch:pattern[ not( @is-a ) ]"><xsl:apply-templates mode="justcopy" select="."/></xsl:when><xsl:when test="self::sch:pattern[ @is-a ]"><xsl:if test="//sch:pattern[@abstract='true'][@id=current()/@is-a]"><xsl:apply-templates mode="justcopy" select="."/></xsl:if></xsl:when><xsl:when test="self::sch:rule[not(preceding-sibling::sch:rule)]"><pattern xmlns="http://purl.oclc.org/dsdl/schematron"><xsl:attribute name="id" select="tei:makePatternID(.)"/><xsl:apply-templates mode="justcopy" select="../sch:rule"/></pattern></xsl:when><xsl:when test="self::sch:rule"/><!-- processed immediately above --><xsl:when test="self::sch:let"/><!-- <let> processed below --><xsl:when test="(self::sch:assert|self::sch:report)[not( preceding-sibling::sch:assert|preceding-sibling::sch:report )]"><pattern xmlns="http://purl.oclc.org/dsdl/schematron"><xsl:attribute name="id" select="tei:makePatternID(.)"/><rule><xsl:attribute name="context"><xsl:choose><!-- in <attDef> in <elementSpec>: --><xsl:when test="ancestor::tei:attDef/ancestor::tei:elementSpec"><xsl:sequence select="tei:generate-nsprefix-schematron(.)"/><xsl:value-of select="ancestor::tei:elementSpec/@ident"/><xsl:text>/@</xsl:text><xsl:value-of select="ancestor::tei:attDef/@ident"/><xsl:text/><!-- what does this do? —Syd, 2020-02-15 --></xsl:when><!-- in <attDef> in something else: --><xsl:when test="ancestor::tei:attDef"><xsl:text>@</xsl:text><xsl:value-of select="ancestor::tei:attDef/@ident"/></xsl:when><xsl:otherwise><!-- ?? I guess we figure we must be in an
<elementSpec>, but I am not at all convinced
that is necessarily true. —Syd, 2020-02-15 --><xsl:sequence select="tei:generate-nsprefix-schematron(.)"/><xsl:value-of select="ancestor::tei:elementSpec/@ident"/></xsl:otherwise></xsl:choose></xsl:attribute><xsl:apply-templates mode="justcopy" select="parent::*/(sch:let|sch:assert|sch:report)"/></rule></pattern></xsl:when><xsl:when test="self::sch:assert|self::sch:report"/><!-- processed immediately above --><xsl:otherwise><xsl:apply-templates mode="justcopy" select="parent::*/sch:let|."/></xsl:otherwise></xsl:choose></xsl:template>
<xsl:template match="tei:elementSpec|tei:classSpec" mode="glossDesc"><!-- We should probably be more careful about the possibility --><!-- of sub-languages (e.g., having descriptions in both 'en-US' and --><!-- 'en-UK'). However, as of now there are no cases of any sublanguages --><!-- that would cause a problem here. --><xsl:variable name="generatedTitleAttrVal"><xsl:if test="tei:gloss[ lang( $targetLanguage ) ]"><xsl:text>(</xsl:text><xsl:apply-templates select="tei:gloss[ lang( $targetLanguage ) ]" mode="glossDescTitle"/><xsl:text>) </xsl:text></xsl:if><xsl:apply-templates select="tei:desc[ lang( $targetLanguage ) ]" mode="glossDescTitle"/></xsl:variable><xsl:value-of select="normalize-space($generatedTitleAttrVal)"/></xsl:template>
<xsl:variable name="anyElement_disambiguator_format" as="xs:string"><!-- A string used as the xsl:number/@format to append to pattern names for <anyElement>s (thus to disambiguate them) --><xsl:variable name="zeroes" as="xs:string+"><xsl:for-each select="1 to ( count( //tei:anyElement ) => xs:string() => string-length() )">0</xsl:for-each></xsl:variable><xsl:value-of select="concat('_', string-join( $zeroes ))"/></xsl:variable>
“normalized minimum and maximum occurences”, pronounced almost as “Norman Max”
Input: an element node, theoretically a member of att.repeatable
Output: a sequence of 4 items:
1) minOccurs as an integer
2) maxOccurs as an integer, with -1 for "unbounded"
3) a string that conforms to xs:NCName, the name of the RELAX NG element that
should be used to generate this number of occurences, if any; one of "optional",
"oneOrMore", "zeroOrMore", or '' (the empty string)
4) a 0- or 1-character long string, the occurence
indicator that should be used to generate this number of
occurences in a DTD, if any; one of '?', '+', '*', or ''
(the empty string)
<xsl:function name="tei:norMinMax" as="item()+"><xsl:param name="me" as="element()"/><!-- get the value of @minOccurs, defaulting to "1" --><xsl:variable name="minOccurs" select="if ( $me/@minOccurs!normalize-space() ne '') then $me/@minOccurs!normalize-space() else '1'"/><!-- get the value of @maxOccurs, defaulting to "1" --><xsl:variable name="maxOccurs" select="if ( $me/@maxOccurs!normalize-space() ne '') then $me/@maxOccurs!normalize-space() else '1'"/><!-- We now have two _string_ representations of the attrs, but --><!-- we need integers. So cast them, converting "unbounded" to --><!-- a special flag value (-1): --><xsl:variable name="min" select="xs:integer( $minOccurs )" as="xs:integer"/><xsl:variable name="max" as="xs:integer"><xsl:choose><xsl:when test="$maxOccurs castable as xs:integer"><!-- It's an integer, but abort if it cannot be used (i.e., min > max) --><xsl:choose><xsl:when test="xs:integer( $maxOccurs ) lt $min"><xsl:message terminate="yes">The default value of @maxOccurs is 1. You cannot have a @minOccurs greater than the @maxOccurs.</xsl:message></xsl:when><xsl:otherwise><xsl:value-of select="xs:integer( $maxOccurs )"/></xsl:otherwise></xsl:choose></xsl:when><xsl:otherwise><!-- Must be "unbounded". --><xsl:value-of select="-1"/></xsl:otherwise></xsl:choose></xsl:variable><!--
Generate the local name of the RELAX NG element used to create
the requested range of occurrences, iff it is one of the
available possiblities. If not, use an empty text node (as a
flag).
--><xsl:variable name="RelaxOccurenceWrapperElementName" as="xs:string"><xsl:choose><xsl:when test="$min eq 0 and $max eq 1">optional</xsl:when><xsl:when test="$min eq 0 and $max eq -1">zeroOrMore</xsl:when><xsl:when test="$min eq 1 and $max eq -1">oneOrMore</xsl:when><xsl:otherwise><xsl:text/></xsl:otherwise></xsl:choose></xsl:variable><!--
Generate the occurence indicator for DTDs, too
--><xsl:variable name="DTD_occurence_indicator" as="xs:string?"><xsl:choose><xsl:when test="$me/tei:textNode | $me/rng:text">*</xsl:when><xsl:when test="$min eq 0 and $max eq 1">?</xsl:when><xsl:when test="$min eq 0 and $max eq -1">*</xsl:when><xsl:when test="$min eq 1 and $max eq -1">+</xsl:when><xsl:otherwise/></xsl:choose></xsl:variable><xsl:sequence select="( $min, $max, $RelaxOccurenceWrapperElementName, $DTD_occurence_indicator )"/></xsl:function>
<xsl:function name="tei:generateRefPrefix" as="xs:string"><xsl:param name="context"/><!-- where we meet a pointer, we have a choice of how to proceed
a) if there is no auto-prefixing, just use as is
b) if the thing exists in the IDENTS table (which includes prefixes), and starts with the prefix, then use it as is
c) if it exists in the IDENTS table and has a prefix, use that
d) otherwise, if it exists in the IDENTS table use the general prefix
e) otherwise, just use what we are given
--><xsl:for-each select="$context"><xsl:variable name="lookup" select="replace(@name|@key,'_(alternation|sequenceOptionalRepeatable|sequenceOptional|sequenceRepeatable|sequence)','')"/><xsl:variable name="myprefix" select="ancestor::*[@prefix][1]/@prefix"/><xsl:variable name="fullname" select="@name|@key"/><xsl:choose><xsl:when test="ancestor::tei:content[@autoPrefix='false']"><xsl:value-of select="$fullname"/></xsl:when><xsl:when test="key('IDENTS',$lookup)"><xsl:for-each select="key('IDENTS',$lookup)[1]"><xsl:choose><xsl:when test="@prefix and starts-with($fullname,@prefix)"><xsl:value-of select="$fullname"/></xsl:when><xsl:when test="@prefix"><xsl:value-of select="concat(@prefix,$fullname)"/></xsl:when><xsl:otherwise><xsl:value-of select="concat($generalPrefix,$fullname)"/></xsl:otherwise></xsl:choose></xsl:for-each></xsl:when><xsl:otherwise><xsl:value-of select="$fullname"/></xsl:otherwise></xsl:choose></xsl:for-each></xsl:function>