|
1 | 1 | <!DOCTYPE xsl:stylesheet>
|
2 | 2 |
|
3 | 3 | <xsl:stylesheet version="3.0"
|
4 |
| - xmlns="http://www.w3.org/1999/xhtml" |
| 4 | + xmlns:h="http://www.w3.org/1999/xhtml" |
| 5 | + xmlns:f="urn:stylesheet-functions" |
5 | 6 | xmlns:xd="http://www.pnp-software.com/XSLTdoc"
|
| 7 | + xmlns:xs="http://www.w3.org/2001/XMLSchema" |
6 | 8 | xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
|
7 |
| - exclude-result-prefixes="xd"> |
| 9 | + exclude-result-prefixes="f h xd"> |
8 | 10 |
|
9 | 11 | <xsl:output indent="no" method="xml" encoding="utf-8"/>
|
10 | 12 |
|
|
14 | 16 |
|
15 | 17 | <xd:doc type="stylesheet">
|
16 | 18 | <xd:short>Stylesheet to preprocess TEI documents.</xd:short>
|
17 |
| - <xd:detail><p>This stylesheet preprocesses TEI documents, so the final conversion to HTML |
18 |
| - can be handled more easily.</p> |
| 19 | + <xd:detail><h:p>This stylesheet preprocesses TEI documents, so the final conversion to HTML |
| 20 | + can be handled more easily.</h:p> |
19 | 21 |
|
20 |
| - <p>The following aspects are handled:</p> |
| 22 | + <h:p>The following aspects are handled:</h:p> |
21 | 23 |
|
22 |
| - <ul> |
23 |
| - <li>1. Strip the TEI namespace if present (see stripns.xsl).</li> |
24 |
| - <li>2. Normalize tables (see normalize-table.xsl).</li> |
25 |
| - <li>3. Remove superfluous attributes.</li> |
26 |
| - </ul> |
| 24 | + <h:ul> |
| 25 | + <h:li>1. Strip the TEI namespace if present (see stripns.xsl).</h:li> |
| 26 | + <h:li>2. Normalize tables (see normalize-table.xsl).</h:li> |
| 27 | + <h:li>3. Remove superfluous attributes.</h:li> |
| 28 | + </h:ul> |
27 | 29 | </xd:detail>
|
28 | 30 | </xd:doc>
|
29 | 31 |
|
|
43 | 45 | </xsl:template>
|
44 | 46 |
|
45 | 47 |
|
| 48 | + <xsl:function name="f:is-margin-note" as="xs:boolean"> |
| 49 | + <xsl:param name="note" as="element(note)"/> |
| 50 | + <xsl:sequence select="$note/@place = 'margin' or $note/@type = 'margin'"/> |
| 51 | + </xsl:function> |
| 52 | + |
| 53 | + <!-- Consecutive marginal notes should be combined into a single marginal note. --> |
| 54 | + <xsl:template match="note[f:is-margin-note(.)]"> |
| 55 | + <xsl:if test="not(preceding-sibling::node()[not(self::text()[normalize-space()=''])][1]/self::note[f:is-margin-note(.)])"> |
| 56 | + <xsl:variable name="siblings" select="(., following-sibling::node())"/> |
| 57 | + <xsl:variable name="notes"> |
| 58 | + <xsl:iterate select="$siblings"> |
| 59 | + <xsl:choose> |
| 60 | + <xsl:when test="self::note[f:is-margin-note(.)]"> |
| 61 | + <xsl:copy-of select="."/> |
| 62 | + </xsl:when> |
| 63 | + <xsl:when test="self::text() and normalize-space(.) = ''"> |
| 64 | + <!-- Skip whitespace --> |
| 65 | + </xsl:when> |
| 66 | + <xsl:otherwise> |
| 67 | + <xsl:break/> |
| 68 | + </xsl:otherwise> |
| 69 | + </xsl:choose> |
| 70 | + </xsl:iterate> |
| 71 | + </xsl:variable> |
| 72 | + |
| 73 | + <!-- Combine the notes, copy the attributes of the first in the sequence. --> |
| 74 | + <note> |
| 75 | + <xsl:for-each select="@*"> |
| 76 | + <xsl:attribute name="{name(.)}" select="."/> |
| 77 | + </xsl:for-each> |
| 78 | + <xsl:for-each select="$notes/note"> |
| 79 | + <xsl:if test="position() > 1"> |
| 80 | + <lb> |
| 81 | + <xsl:if test="@id"> |
| 82 | + <xsl:attribute name="id" select="@id"/> |
| 83 | + </xsl:if> |
| 84 | + <xsl:message>INFO: merged consecutive marginal notes.</xsl:message> |
| 85 | + </lb> |
| 86 | + </xsl:if> |
| 87 | + <xsl:apply-templates/> |
| 88 | + </xsl:for-each> |
| 89 | + </note> |
| 90 | + </xsl:if> |
| 91 | + </xsl:template> |
| 92 | + |
| 93 | + <!-- Suppress individual notes that are merged --> |
| 94 | + <xsl:template match="note[f:is-margin-note(.)][preceding-sibling::node()[not(self::text()[normalize-space()=''])][1]/self::note[f:is-margin-note(.)]]" priority="1"/> |
| 95 | + |
46 | 96 | <!-- Two consecutive "phantom"-elements can be merged -->
|
47 | 97 |
|
48 | 98 | <xsl:template match="ab[@type='phantom']" mode="#all">
|
|
0 commit comments