TEI Utility stylesheet defining functions for use in all
output formats.
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.
[common] handle character data.
Following http://wiki.tei-c.org/index.php/XML_Whitespace#XSLT_Normalization_Code,
the algorithm to normalize space in mixed content is:
Collapse all white space, then
trim leading space on the first text node in an element and
trim trailing space on the last text node in an element,
trim both if a text node is both first and last, i.e., is the only text node in the
element.
<xsl:template match="text()"><xsl:choose><xsl:when test="ancestor::*[@xml:space][1]/@xml:space='preserve'"><xsl:value-of select="tei:escapeChars(.,parent::*)"/></xsl:when><xsl:otherwise><!-- Retain one leading space if node isn't first, has
non-space content, and has leading space.--><xsl:if test="position()!=1 and matches(.,'^\s') and normalize-space()!=''"><xsl:text></xsl:text></xsl:if><xsl:value-of select="tei:escapeChars(normalize-space(.),parent::*)"/><xsl:choose><!-- node is an only child, and has content but it's all space --><xsl:when test="last()=1 and string-length()!=0 and normalize-space()=''"><xsl:text></xsl:text></xsl:when><!-- node isn't last, isn't first, and has trailing space --><xsl:when test="position()!=1 and position()!=last() and matches(.,'\s$')"><xsl:text></xsl:text></xsl:when><!-- node isn't last, is first, has trailing space, and has non-space content --><xsl:when test="position()=1 and matches(.,'\s$') and normalize-space()!=''"><xsl:text></xsl:text></xsl:when></xsl:choose></xsl:otherwise></xsl:choose></xsl:template>
<xsl:function name="tei:keepDivOnPage" as="xs:boolean"><xsl:param name="context"/><xsl:param name="depth"/><xsl:for-each select="$context"><xsl:choose><!-- 4. we are part of an inner text --><xsl:when test="ancestor::tei:floatingText">true</xsl:when><!-- 3. we have special rendering on the document --><xsl:when test="ancestor::tei:TEI/@rend='all' or ancestor::tei:TEI/@rend='frontpage' or ancestor::tei:TEI/@rend='nosplit'">true</xsl:when><!-- 2. we are a singleton --><xsl:when test="parent::tei:body[count(*)=1]">true</xsl:when><!-- 1. we have no proceding sections at top level --><xsl:when test="parent::tei:body and not(parent::tei:body/preceding-sibling::tei:front) and not (preceding-sibling::*)">true</xsl:when><!-- 0. we are down the hierarchy --><xsl:when test="@rend='nosplit'">true</xsl:when><xsl:otherwise>false</xsl:otherwise></xsl:choose></xsl:for-each></xsl:function>