Commit 5a94addf authored by Dennis Neumann's avatar Dennis Neumann
Browse files

Add source description and do not always strip space between elements

parent 602fa41c
......@@ -5,7 +5,7 @@
xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:saxon="http://saxon.sf.net/" exclude-result-prefixes="gfl saxon xs">
<xsl:output method="xml" indent="yes" />
<xsl:strip-space elements="*" />
<xsl:template match="/">
<add>
......@@ -21,7 +21,9 @@
<xsl:template match="text()" mode="#all">
<xsl:value-of select="replace(., '\s+', ' ')" />
<xsl:variable name="current" select="normalize-space(.)" />
<xsl:variable name="next" select="normalize-space(following::text()[1])" />
<xsl:value-of select="if ($current='' and $next='') then '' else replace(., '\s+', ' ')" />
</xsl:template>
......@@ -36,6 +38,7 @@
<xsl:apply-templates select="titleStmt/title[@type='desc']/name" />
<xsl:apply-templates select="titleStmt/title[@type='desc']/date[@type='orn']" />
<xsl:apply-templates select="titleStmt/author/name" />
<xsl:apply-templates select="sourceDesc" />
</xsl:template>
<xsl:template match="title[@type='short']">
......@@ -79,6 +82,12 @@
<xsl:apply-templates mode="text_only" />
</field>
</xsl:template>
<xsl:template match="sourceDesc">
<field name="source_description">
<xsl:apply-templates mode="text_only" />
</field>
</xsl:template>
<!--################### text/body ##########################-->
......
......@@ -35,6 +35,13 @@ public class XsltTest {
System.out.println(outputBaos.toString());
}
@Test
public void sourceDescription() throws Exception {
String result = transform("sourceDesc.xml");
assertXpathEvaluatesTo(" DE Weimar", "//field[@name='source_description']", result);
}
@Test
public void date() throws Exception {
String result = transform("date.xml");
......@@ -102,28 +109,28 @@ public class XsltTest {
public void note_removesIfIsAComment() throws Exception {
String result = transform("note-comment.xml");
assertXpathEvaluatesTo("before-note after-note", "//field[@name='fulltext']", result);
assertXpathEvaluatesTo(" before-note after-note", "//field[@name='fulltext']", result);
}
@Test
public void twoLinebreaks_replacesWithSpaces() throws Exception {
String result = transform("linebreaks-two.xml");
assertXpathEvaluatesTo("before middle after", "//field[@name='fulltext']", result);
assertXpathEvaluatesTo(" before middle after", "//field[@name='fulltext']", result);
}
@Test
public void linebreak_replacesWithSpace() throws Exception {
String result = transform("linebreak.xml");
assertXpathEvaluatesTo("before after", "//field[@name='fulltext']", result);
assertXpathEvaluatesTo(" before after", "//field[@name='fulltext']", result);
}
@Test
public void basicTest_fulltext() throws Exception {
String result = transform("fulltext.xml");
assertXpathEvaluatesTo("Test text.", "//field[@name='fulltext']", result);
assertXpathEvaluatesTo(" Test text.", "//field[@name='fulltext']", result);
}
private String transform(String fileName) throws SaxonApiException {
......
<?xml version="1.0" encoding="UTF-8"?>
<TEI xmlns="http://www.tei-c.org/ns/1.0">
<teiHeader>
<fileDesc>
<sourceDesc>
<msDesc xml:lang="ger">
<msIdentifier>
<country>DE</country>
<settlement ref="gnd:123">Weimar</settlement>
</msIdentifier>
</msDesc>
</sourceDesc>
</fileDesc>
</teiHeader>
<text xml:id="my_id" xml:lang="ger">
<body>
</body>
</text>
</TEI>
\ No newline at end of file
......@@ -56,6 +56,7 @@
<field name="origin_place" type="text_de" multiValued="false" />
<field name="destination_place" type="text_de" multiValued="false" />
<field name="origin_date" type="date" />
<field name="source_description" type="text_de" multiValued="true" />
<!-- transaction log -->
<field name="_version_" type="long" indexed="true" stored="true" />
......
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