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" />
</field>
</xsl:template>
......@@ -113,6 +113,13 @@
<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 select="*" mode="html_for_whole_article" />
</div>
<xsl:text disable-output-escaping="yes">]]&gt;</xsl:text>
</field>
</xsl:template>
<xsl:template match="body | div" mode="text_only">
......@@ -130,5 +137,24 @@
<xsl:template match="note[@type='com']" mode="text_only">
</xsl:template>
<!-- ++++++++++++ HTML +++++++++++++++++++ -->
<xsl:template match="opener" mode="html_for_whole_article">
<div class="opener">
<xsl:apply-templates mode="html_for_whole_article" />
</div>
</xsl:template>
<xsl:template match="salute" mode="html_for_whole_article">
<div class="salute">
<xsl:apply-templates mode="html_for_whole_article" />
</div>
</xsl:template>
<xsl:template match="lb" mode="html_for_whole_article">
<br />
</xsl:template>
</xsl:stylesheet>
\ No newline at end of file
package sub.gfl;
import static org.junit.Assert.*;
import static org.custommonkey.xmlunit.XMLAssert.*;
import java.io.ByteArrayOutputStream;
import java.io.OutputStream;
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;
@BeforeClass
public static void beforeAllTests() throws Exception {
xslt = new Xslt();
xslt.setXsltScript("src/main/resources/gfl-indexer.xslt");
}
@Before
public void beforeEachTest() throws Exception {
outputBaos = new ByteArrayOutputStream();
}
@After
public void afterEachTest() {
System.out.println(outputBaos.toString());
}
@Test
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 = matcher.group(1);
}
return html;
}
}
<?xml version="1.0" encoding="UTF-8"?>
<TEI xmlns="http://www.tei-c.org/ns/1.0">
<teiHeader>
</teiHeader>
<text xml:id="my_id" xml:lang="ger">
<body>
<div>
<opener>
<salute rendition="simple:centre">Hochwohlgebohrener
Herr<lb/>und Staatsminister,</salute>
</opener>
</div>
</body>
</text>
</TEI>
\ 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