Commit 7b5cd42a authored by Dennis Neumann's avatar Dennis Neumann
Browse files

Refactor XSLT

parent f1fe8c54
......@@ -5,7 +5,8 @@
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:preserve-space elements="msIdentifier" />
<xsl:template match="/">
<add>
......@@ -19,13 +20,9 @@
<xsl:apply-templates select="teiHeader | text" />
</xsl:template>
<xsl:template match="text()" mode="#all">
<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:value-of select="replace(., '\s+', ' ')" />
</xsl:template>
<!--########### Header #######################-->
......@@ -114,9 +111,18 @@
<xsl:value-of select="@xml:id" />
</field>
<field name="fulltext">
<xsl:apply-templates select="body/*" mode="text_only" />
<xsl:apply-templates select="body" mode="text_only" />
</field>
</xsl:template>
<xsl:template match="body | div" mode="text_only">
<xsl:apply-templates select="*" mode="text_only"/>
</xsl:template>
<xsl:template match="p" mode="text_only">
<xsl:apply-templates mode="text_only" />
<xsl:text> </xsl:text>
</xsl:template>
<xsl:template match="lb" mode="text_only">
<xsl:text> </xsl:text>
......
......@@ -55,7 +55,7 @@ public class XsltTest {
public void sourceDescription() throws Exception {
String result = transform("sourceDesc.xml");
assertXpathEvaluatesTo(" DE Weimar", "//field[@name='source_description']", result);
assertXpathEvaluatesTo(" DE Weimar ", "//field[@name='source_description']", result);
}
@Test
......@@ -125,28 +125,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 {
......
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