Commit 4d87e7d0 authored by Dennis Neumann's avatar Dennis Neumann
Browse files

Start combining split pages and complete articles in the same XSLT templates

parent 6a8dfc7d
......@@ -52,7 +52,7 @@ Furthermore, a warning message is generated that contains data of the first occu
<doc>
<xsl:apply-templates select="teiHeader | text" />
</doc>
<xsl:apply-templates select="text/body/div" mode="page_splitting" />
<xsl:apply-templates select="text" mode="page_splitting" />
</add>
</xsl:template>
......@@ -174,14 +174,29 @@ Furthermore, a warning message is generated that contains data of the first occu
<field name="id">
<xsl:value-of select="@xml:id" />
</field>
<field name="doctype">whole_article</field>
<field name="doctype">article</field>
<field name="number_of_pages">
<xsl:value-of select="count(//pb)" />
</field>
<field name="fulltext">
<xsl:apply-templates select="body" mode="text_only" />
</field>
<field name="fulltext_html">
<xsl:text disable-output-escaping="yes">&lt;![CDATA[</xsl:text>
<div class="article">
<xsl:apply-templates mode="html_for_whole_article" />
<xsl:variable name="context" select="." />
<xsl:for-each-group select="descendant::node()[not(node())]" group-starting-with="pb">
<xsl:if test="self::pb">
<div class="page">
<div class="page-beginning">
<xsl:value-of select="self::pb/@n" />
</div>
<xsl:apply-templates select="$context/*" mode="page_splitting">
<xsl:with-param name="restricted-to" select="current-group()/ancestor-or-self::node()" tunnel="yes" />
</xsl:apply-templates>
</div>
</xsl:if>
</xsl:for-each-group>
</div>
<xsl:text disable-output-escaping="yes">]]&gt;</xsl:text>
</field>
......@@ -427,7 +442,7 @@ Furthermore, a warning message is generated that contains data of the first occu
<!-- %%%%%%%%%%%%% page splitting %%%%%%%%%%%%%%%%%%%%%%% -->
<xsl:template match="div" mode="page_splitting">
<xsl:template match="text" mode="page_splitting">
<xsl:variable name="context" select="." />
<xsl:for-each-group select="descendant::node()[not(node())]" group-starting-with="pb">
<xsl:if test="self::pb">
......@@ -441,7 +456,7 @@ Furthermore, a warning message is generated that contains data of the first occu
<field name="article_id">
<xsl:value-of select="$context/../../@xml:id" />
</field>
<field name="doctype">one_page</field>
<field name="doctype">page</field>
<field name="page_number">
<xsl:value-of select="$pageNumber" />
</field>
......@@ -462,7 +477,41 @@ Furthermore, a warning message is generated that contains data of the first occu
</xsl:for-each-group>
</xsl:template>
<xsl:template match="p | name" mode="page_splitting">
<xsl:template match="pb" mode="page_splitting" />
<xsl:template match="*" mode="page_splitting">
<xsl:param name="restricted-to" tunnel="yes" />
<xsl:if test="exists(. intersect $restricted-to)">
<xsl:message>
<xsl:text>Unknown element &lt;</xsl:text>
<xsl:value-of select="local-name()" />
<xsl:if test="@rendition">
<xsl:text> rendition="</xsl:text>
<xsl:value-of select="@rendition" />
<xsl:text>"</xsl:text>
</xsl:if>
<xsl:if test="@type">
<xsl:text> type="</xsl:text>
<xsl:value-of select="@type" />
<xsl:text>"</xsl:text>
</xsl:if>
<xsl:text>&gt; - first occurrence: </xsl:text>
</xsl:message>
<span class="unknown-element">
<xsl:apply-templates mode="page_splitting" />
</span>
</xsl:if>
</xsl:template>
<xsl:template match="body | div | front" mode="page_splitting">
<xsl:param name="restricted-to" tunnel="yes" />
<xsl:if test="exists(. intersect $restricted-to)">
<xsl:apply-templates mode="page_splitting" />
</xsl:if>
</xsl:template>
<xsl:template match="p | opener | salute | seg | bibl | closer | signed | dateline | date
| label[not(@rendition)] | choice | abbr | expan | postscript" mode="page_splitting">
<xsl:param name="restricted-to" tunnel="yes" />
<xsl:if test="exists(. intersect $restricted-to)">
<div class="{local-name(.)}">
......@@ -474,10 +523,203 @@ Furthermore, a warning message is generated that contains data of the first occu
<xsl:template match="text()" mode="page_splitting">
<xsl:param name="restricted-to" tunnel="yes" />
<xsl:if test="exists(. intersect $restricted-to)">
<xsl:copy />
<xsl:variable name="currentText" select="replace(., '\s+', ' ')" />
<xsl:choose>
<xsl:when test="ends-with(., '&#0173;')">
<xsl:value-of select="replace($currentText, '&#0173;', '-')" />
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$currentText" />
</xsl:otherwise>
</xsl:choose>
</xsl:if>
</xsl:template>
<xsl:template match="lb" mode="page_splitting">
<xsl:param name="restricted-to" tunnel="yes" />
<xsl:if test="exists(. intersect $restricted-to)">
<br />
</xsl:if>
</xsl:template>
<xsl:template match="pb" mode="page_splitting" />
<xsl:template match="space[@unit='lines']" mode="page_splitting">
<xsl:param name="restricted-to" tunnel="yes" />
<xsl:if test="exists(. intersect $restricted-to)">
<xsl:variable name="emptyLines" select="@quantity" />
<xsl:choose>
<xsl:when test="$emptyLines castable as xs:integer">
<xsl:for-each select="1 to $emptyLines">
<br />
</xsl:for-each>
</xsl:when>
<xsl:otherwise>
<br />
</xsl:otherwise>
</xsl:choose>
</xsl:if>
</xsl:template>
<xsl:template match="name[@type='place']" mode="page_splitting">
<xsl:param name="restricted-to" tunnel="yes" />
<xsl:if test="exists(. intersect $restricted-to)">
<div class="place">
<xsl:apply-templates mode="page_splitting" />
</div>
</xsl:if>
</xsl:template>
<xsl:template match="name[@type='org']" mode="page_splitting">
<xsl:param name="restricted-to" tunnel="yes" />
<xsl:if test="exists(. intersect $restricted-to)">
<div class="org">
<xsl:apply-templates mode="page_splitting" />
</div>
</xsl:if>
</xsl:template>
<xsl:template match="name[@type='person']" mode="page_splitting">
<xsl:param name="restricted-to" tunnel="yes" />
<xsl:if test="exists(. intersect $restricted-to)">
<div class="person">
<xsl:apply-templates mode="page_splitting" />
</div>
</xsl:if>
</xsl:template>
<xsl:template match="name[@type='object']" mode="page_splitting">
<xsl:param name="restricted-to" tunnel="yes" />
<xsl:if test="exists(. intersect $restricted-to)">
<div class="object">
<xsl:apply-templates mode="page_splitting" />
</div>
</xsl:if>
</xsl:template>
<xsl:template match="rs[@type='person']" mode="page_splitting">
<xsl:param name="restricted-to" tunnel="yes" />
<xsl:if test="exists(. intersect $restricted-to)">
<div class="rs-person">
<xsl:apply-templates mode="page_splitting" />
</div>
</xsl:if>
</xsl:template>
<xsl:template match="rs[@type='place']" mode="page_splitting">
<xsl:param name="restricted-to" tunnel="yes" />
<xsl:if test="exists(. intersect $restricted-to)">
<div class="rs-place">
<xsl:apply-templates mode="page_splitting" />
</div>
</xsl:if>
</xsl:template>
<xsl:template match="note[@type='com']" mode="page_splitting">
<xsl:param name="restricted-to" tunnel="yes" />
<xsl:if test="exists(. intersect $restricted-to)">
<div class="note-comment">
<xsl:apply-templates mode="page_splitting" />
</div>
</xsl:if>
</xsl:template>
<xsl:template match="note[@type='footnote']" mode="page_splitting">
<xsl:param name="restricted-to" tunnel="yes" />
<xsl:if test="exists(. intersect $restricted-to)">
<div class="note-footnote">
<xsl:apply-templates mode="page_splitting" />
</div>
</xsl:if>
</xsl:template>
<xsl:template match="note[not(@type)]" mode="page_splitting">
<xsl:param name="restricted-to" tunnel="yes" />
<xsl:if test="exists(. intersect $restricted-to)">
<div class="note">
<xsl:apply-templates mode="page_splitting" />
</div>
</xsl:if>
</xsl:template>
<xsl:template match="hi[@rendition='simple:underline']" mode="page_splitting">
<xsl:param name="restricted-to" tunnel="yes" />
<xsl:if test="exists(. intersect $restricted-to)">
<div class="underline">
<xsl:apply-templates mode="page_splitting" />
</div>
</xsl:if>
</xsl:template>
<xsl:template match="hi[@rendition='simple:doubleunderline']" mode="page_splitting">
<xsl:param name="restricted-to" tunnel="yes" />
<xsl:if test="exists(. intersect $restricted-to)">
<div class="doubleunderline">
<xsl:apply-templates mode="page_splitting" />
</div>
</xsl:if>
</xsl:template>
<xsl:template match="hi[@rendition='simple:superscript']" mode="page_splitting">
<xsl:param name="restricted-to" tunnel="yes" />
<xsl:if test="exists(. intersect $restricted-to)">
<sup>
<xsl:apply-templates mode="page_splitting" />
</sup>
</xsl:if>
</xsl:template>
<xsl:template match="hi[@rendition='simple:subscript']" mode="page_splitting">
<xsl:param name="restricted-to" tunnel="yes" />
<xsl:if test="exists(. intersect $restricted-to)">
<sub>
<xsl:apply-templates mode="page_splitting" />
</sub>
</xsl:if>
</xsl:template>
<xsl:template match="hi[@rendition='simple:italic']" mode="page_splitting">
<xsl:param name="restricted-to" tunnel="yes" />
<xsl:if test="exists(. intersect $restricted-to)">
<div class="italic">
<xsl:apply-templates mode="page_splitting" />
</div>
</xsl:if>
</xsl:template>
<xsl:template match="hi[@rendition='simple:letterspace']" mode="page_splitting">
<xsl:param name="restricted-to" tunnel="yes" />
<xsl:if test="exists(. intersect $restricted-to)">
<div class="letterspace">
<xsl:apply-templates mode="page_splitting" />
</div>
</xsl:if>
</xsl:template>
<xsl:template match="hi[@rendition='simple:right']" mode="page_splitting">
<xsl:param name="restricted-to" tunnel="yes" />
<xsl:if test="exists(. intersect $restricted-to)">
<div class="right">
<xsl:apply-templates mode="page_splitting" />
</div>
</xsl:if>
</xsl:template>
<xsl:template match="ref[@target]" mode="page_splitting">
<xsl:param name="restricted-to" tunnel="yes" />
<xsl:if test="exists(. intersect $restricted-to)">
<a href="{@target}">
<xsl:apply-templates mode="page_splitting" />
</a>
</xsl:if>
</xsl:template>
<xsl:template match="head[@rendition] | label[@rendition]" mode="page_splitting">
<xsl:param name="restricted-to" tunnel="yes" />
<xsl:if test="exists(. intersect $restricted-to)">
<xsl:variable name="classNames" select="local-name(), substring-after(@rendition, 'simple:')" />
<div class="{$classNames}">
<xsl:apply-templates mode="page_splitting" />
</div>
</xsl:if>
</xsl:template>
</xsl:stylesheet>
\ No newline at end of file
......@@ -40,7 +40,7 @@ public class XsltHtmlTest {
public void pageBreak_findsCorrespondingUrlInFacsimile() throws Exception {
String html = transform("page-break_with-graphic-url.xml");
assertXpathEvaluatesTo("/my-graphic", "//div[@class='page-break']/a/@href", html);
assertXpathEvaluatesTo("/my-graphic", "//div[@class='page-beginning']/a/@href", html);
}
@Test
......@@ -195,19 +195,12 @@ public class XsltHtmlTest {
assertXpathEvaluatesTo("My org", "//div[@class='org']", html);
}
@Test
public void pageBreak_doesNotGenerateLink() throws Exception {
String html = transform("page-break_with-empty-page-id.xml");
assertXpathEvaluatesTo("", "//a/@href", html);
}
@Test
public void pageBreak() throws Exception {
String html = transform("page-break.xml");
assertXpathEvaluatesTo("page-id", "//div[@class='page-break']", html);
assertXpathEvaluatesTo("2", "count(//div[@class='page'])", html);
}
@Test
......@@ -229,14 +222,14 @@ public class XsltHtmlTest {
public void zeroPointSixLines_generateOneBreak() throws Exception {
String html = transform("spaceLines_zeroPointSixLines.xml");
assertXpathEvaluatesTo("1", "count(/div[@class='article']/br)", html);
assertXpathEvaluatesTo("1", "count(/div[@class='article']//br)", html);
}
@Test
public void spaceLines_generateBreaks() throws Exception {
String html = transform("spaceLines.xml");
assertXpathEvaluatesTo("2", "count(/div[@class='article']/br)", html);
assertXpathEvaluatesTo("2", "count(/div[@class='article']//br)", html);
}
@Test
......
......@@ -44,6 +44,13 @@ public class XsltSplitTest {
String htmlPage2 = transform("two-page-beginnings.xml", 2);
assertXpathEvaluatesTo("Second page", "//div[@class='p'][1]", htmlPage2);
}
@Test
public void givesNumberOfPages() throws Exception {
xslt.transform("src/test/resources/tei-snippets-split/" + "two-page-beginnings.xml", outputBaos);
String xml = outputBaos.toString();
assertXpathEvaluatesTo("2", "//field[@name='number_of_pages']", xml);
}
private String transform(String fileName, int pageNumber) throws Exception {
......
......@@ -5,6 +5,7 @@
<text xml:id="my_id" xml:lang="ger">
<body>
<div>
<pb />
<p>before <bibl><ref
target="http://bla.com"
>my link</ref></bibl> after</p>
......
......@@ -5,6 +5,7 @@
<text xml:id="my_id" xml:lang="ger">
<body>
<div>
<pb />
<p>before
<choice>
<abbr>d.</abbr>
......
......@@ -5,6 +5,7 @@
<text xml:id="my_id" xml:lang="ger">
<body>
<div>
<pb />
<closer>
<salute>mfg</salute>
</closer>
......
......@@ -5,6 +5,7 @@
<text xml:id="my_id" xml:lang="ger">
<body>
<div>
<pb />
<closer>
<dateline>before <date when="1822-01-19">1821</date> after</dateline>
</closer>
......
......@@ -5,6 +5,7 @@
<text xml:id="my_id" xml:lang="ger">
<body>
<div>
<pb />
<head rendition="simple:column-right">column to the right</head>
<head rendition="simple:centre">in the center</head>
<head rendition="simple:underline">underlined head</head>
......
......@@ -5,6 +5,7 @@
<text xml:id="my_id" xml:lang="ger">
<body>
<div>
<pb />
<p>before <hi
rendition="simple:underline">underlined</hi> <hi
rendition="simple:superscript">superscripted</hi> <hi
......
......@@ -5,6 +5,7 @@
<text xml:id="my_id" xml:lang="ger">
<body>
<div>
<pb />
<p>auf­<lb/> und ab</p>
</div>
</body>
......
......@@ -5,6 +5,7 @@
<text xml:id="my_id" xml:lang="ger">
<body>
<div>
<pb />
<p>before <label>my-label</label> after</p>
</div>
</body>
......
......@@ -5,6 +5,7 @@
<text xml:id="my_id" xml:lang="ger">
<body>
<div>
<pb />
<label rendition="simple:centre">label in the center</label>
</div>
</body>
......
......@@ -5,6 +5,7 @@
<text xml:id="my_id" xml:lang="ger">
<body>
<div>
<pb />
<p>before <name type="place">Jena</name> after</p>
</div>
</body>
......
......@@ -5,6 +5,7 @@
<text xml:id="my_id" xml:lang="ger">
<body>
<div>
<pb />
<p>before-note<note type="com">A note.</note> after-note</p>
</div>
</body>
......
......@@ -5,6 +5,7 @@
<text xml:id="my_id" xml:lang="ger">
<body>
<div>
<pb />
<p>before-note<note type="footnote">A note.</note> after-note</p>
</div>
</body>
......
......@@ -5,6 +5,7 @@
<text xml:id="my_id" xml:lang="ger">
<body>
<div>
<pb />
<p>before-note<note place="end">A note.</note> after-note</p>
</div>
</body>
......
......@@ -5,6 +5,7 @@
<text xml:id="my_id" xml:lang="ger">
<body>
<div>
<pb />
<p>before <name type="object">my object</name> after</p>
</div>
</body>
......
......@@ -6,6 +6,7 @@
<body>
<div>
<opener>
<pb />
<salute rendition="simple:centre">Hochwohlgebohrener
Herr<lb/>und Staatsminister,</salute>
</opener>
......
......@@ -5,6 +5,7 @@
<text xml:id="my_id" xml:lang="ger">
<body>
<div>
<pb />
<p>before <name type="org">My org</name> after</p>
</div>
</body>
......
......@@ -5,6 +5,7 @@
<text xml:id="my_id" xml:lang="ger">
<body>
<div>
<pb />
<p>before<pb n="page-id"/>after</p>
</div>
</body>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment