Commit 903cc960 authored by Dennis Neumann's avatar Dennis Neumann
Browse files

Replace linebreaks with spaces

parent 1a5cd702
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xpath-default-namespace="http://www.tei-c.org/ns/1.0" xmlns:gfl="http://sub.gfl.de"
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:param name="currentArticleId" />
<xsl:template match="/">
<add>
<doc>
<field name="id">
<xsl:value-of select="$currentArticleId" />
</field>
<field name="fulltext">
<xsl:value-of select="TEI/text/body" />
</field>
</doc>
</add>
</xsl:template>
xpath-default-namespace="http://www.tei-c.org/ns/1.0" xmlns:gfl="http://sub.gfl.de"
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:param name="currentArticleId" />
<xsl:template match="/">
<add>
<doc>
<field name="id">
<xsl:value-of select="$currentArticleId" />
</field>
<field name="fulltext">
<xsl:apply-templates select="TEI/text/body/*" />
</field>
</doc>
</add>
</xsl:template>
<xsl:template match="p">
<xsl:apply-templates select="*|text()" />
</xsl:template>
<xsl:template match="text()">
<xsl:value-of select="." />
</xsl:template>
<xsl:template match="lb">
<xsl:text> </xsl:text>
</xsl:template>
</xsl:stylesheet>
\ No newline at end of file
......@@ -35,6 +35,20 @@ public class XsltTest {
System.out.println(outputBaos.toString());
}
@Test
public void twoLinebreaks_replaceWithSpaces() throws Exception {
String result = transform("linebreaks-two.xml");
assertXpathEvaluatesTo("before middle after", "//field[@name='fulltext']", result);
}
@Test
public void linebreak_replaceWithSpace() throws Exception {
String result = transform("linebreak.xml");
assertXpathEvaluatesTo("before after", "//field[@name='fulltext']", result);
}
@Test
public void basicTest_idAndFulltext() throws Exception {
xslt.setParameter("currentArticleId", "my-id");
......@@ -42,6 +56,8 @@ public class XsltTest {
assertXpathEvaluatesTo("my-id", "//field[@name='id']", result);
assertXpathEvaluatesTo("Test text.", "//field[@name='fulltext']", result);
xslt.setParameter("currentArticleId", null);
}
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>
</teiHeader>
<text xml:id="my_id" xml:lang="ger">
<body>
<div>
<p>before<lb/>after</p>
</div>
</body>
</text>
</TEI>
\ No newline at end of file
<?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>
<p>before<lb/>middle<lb/>after</p>
</div>
</body>
</text>
</TEI>
\ No newline at end of file
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