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="processing-instruction()"><xsl:choose><xsl:when test="name(.) = 'odds'"><xsl:choose><xsl:when test=".='date'">This formatted version of the Guidelines was created on<xsl:call-template name="showDate"/>.</xsl:when></xsl:choose></xsl:when><xsl:otherwise><xsl:copy-of select="."/></xsl:otherwise></xsl:choose></xsl:template>
<xsl:template match="rng:group"><!-- 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><group xmlns="http://relaxng.org/ns/structure/1.0"><xsl:copy-of select="@*"/><xsl:apply-templates select="rng:*|tei:*|text()|comment()"/></group></xsl:otherwise></xsl:choose></xsl:when><xsl:otherwise><xsl:element name="{local-name()}" xmlns="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>
<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="bitOut"><xsl:with-param name="grammar">true</xsl:with-param><xsl:with-param name="content"><Wrapper><xsl:choose><xsl:when test="@url and $parameterize='true'"><include xmlns="http://relaxng.org/ns/structure/1.0" href="{@url}"><xsl:apply-templates mode="justcopy" select="tei:content/*"/></include></xsl:when><xsl:when test="@url and $parameterize='false'"><xsl:comment>Start of import of <xsl:value-of select="@url"/></xsl:comment><div xmlns="http://relaxng.org/ns/structure/1.0"><xsl:for-each select="document(@url)/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:apply-templates mode="justcopy" select="tei:content/*"/></div><xsl:comment>End of import of <xsl:value-of select="@url"/></xsl:comment></xsl:when><xsl:otherwise><include xmlns="http://relaxng.org/ns/structure/1.0" 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></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><attribute xmlns="http://relaxng.org/ns/structure/1.0" 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:call-template name="makeDescription"><xsl:with-param name="includeValList">true</xsl:with-param><xsl:with-param name="coded">false</xsl:with-param></xsl:call-template></a:documentation></xsl:if><!-- ************************************ --><!-- Ascertain minOccurs= and maxOccurs=. --><!-- ************************************ --><!-- get the value of minOccurs=, defaulting to "1" --><xsl:variable name="minOccurs"><xsl:choose><xsl:when test="tei:datatype/@minOccurs"><xsl:value-of select="tei:datatype/@minOccurs"/></xsl:when><xsl:otherwise>1</xsl:otherwise></xsl:choose></xsl:variable><!-- get the value of maxOccurs=, defaulting to "1" --><xsl:variable name="maxOccurs"><xsl:choose><xsl:when test="tei:datatype/@maxOccurs"><xsl:value-of select="tei:datatype/@maxOccurs"/></xsl:when><xsl:otherwise>1</xsl:otherwise></xsl:choose></xsl:variable><!-- 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 )"/><xsl:variable name="max"><xsl:choose><xsl:when test="$maxOccurs='unbounded'"><xsl:value-of select="xs:integer( -1 )"/></xsl:when><xsl:otherwise><xsl:value-of select="xs:integer( $maxOccurs )"/></xsl:otherwise></xsl:choose></xsl:variable><xsl:choose><xsl:when test="tei:datatype/rng:text or not( tei:datatype ) or $max=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="."/><list><xsl:if test="$min > 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= -1"><!-- i.e., unbounded --><zeroOrMore><xsl:for-each select="$thisNode"><xsl:call-template name="attributeData"/></xsl:for-each></zeroOrMore></xsl:when><xsl:otherwise><xsl:for-each select="xs:integer( $min + 1 ) to $max"><optional><xsl:for-each select="$thisNode"><xsl:call-template name="attributeData"/></xsl:for-each></optional></xsl:for-each></xsl:otherwise></xsl:choose></list></xsl:otherwise></xsl:choose></attribute></xsl:template>