Commit b49f6ff1 authored by Dennis Neumann's avatar Dennis Neumann
Browse files

Start generating HTML

parent b137862a
......@@ -56,7 +56,7 @@
<xsl:template match="title/name[@type='place' and @subtype='orn']">
<field name="origin_place">
<xsl:apply-templates select="*|text()" mode="text_only" />
<xsl:apply-templates mode="text_only" />
......@@ -113,6 +113,13 @@
<field name="fulltext">
<xsl:apply-templates select="body" mode="text_only" />
<field name="fulltext_html">
<xsl:text disable-output-escaping="yes">&lt;![CDATA[</xsl:text>
<div class="article">
<xsl:apply-templates select="*" mode="html_for_whole_article" />
<xsl:text disable-output-escaping="yes">]]&gt;</xsl:text>
<xsl:template match="body | div" mode="text_only">
......@@ -130,5 +137,24 @@
<xsl:template match="note[@type='com']" mode="text_only">
<!-- ++++++++++++ HTML +++++++++++++++++++ -->
<xsl:template match="opener" mode="html_for_whole_article">
<div class="opener">
<xsl:apply-templates mode="html_for_whole_article" />
<xsl:template match="salute" mode="html_for_whole_article">
<div class="salute">
<xsl:apply-templates mode="html_for_whole_article" />
<xsl:template match="lb" mode="html_for_whole_article">
<br />
\ No newline at end of file
package sub.gfl;
import static org.junit.Assert.*;
import static org.custommonkey.xmlunit.XMLAssert.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.junit.After;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import sub.ent.backend.Xslt;
public class XsltHtmlTest {
private OutputStream outputBaos;
private static Xslt xslt;
public static void beforeAllTests() throws Exception {
xslt = new Xslt();
public void beforeEachTest() throws Exception {
outputBaos = new ByteArrayOutputStream();
public void afterEachTest() {
public void should() throws Exception {
String html = transform("opener-and-salute.xml");
assertXpathExists("//div[@class='opener']/div[@class='salute']/br", html);
assertXpathEvaluatesTo("Hochwohlgebohrener Herrund Staatsminister,", "//div[@class='salute']", html);
private String transform(String fileName) throws Exception {
xslt.transform("src/test/resources/tei-snippets/" + fileName, outputBaos);
return extractHtmlField(outputBaos.toString());
private String extractHtmlField(String s) {
Pattern pattern = Pattern.compile("fulltext_html\"><!\\[CDATA\\[(.*?)]]");
Matcher matcher = pattern.matcher(s.replaceAll("\\n", " "));
String html = "";
if (matcher.find()) {
html =;
return html;
<?xml version="1.0" encoding="UTF-8"?>
<TEI xmlns="">
<text xml:id="my_id" xml:lang="ger">
<salute rendition="simple:centre">Hochwohlgebohrener
Herr<lb/>und Staatsminister,</salute>
\ No newline at end of file
......@@ -49,6 +49,7 @@
<field name="type" type="string" required="false" />
<field name="fulltext" type="text_de" multiValued="false" />
<field name="fulltext_html" type="text_de" multiValued="false" />
<field name="short_title" type="text_de" multiValued="false" />
<field name="title" type="text_de" multiValued="false" />
<field name="author" type="text_de" multiValued="false" />
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