forked from UB-Mannheim/ocr-fileformat
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpage__text.xsl
44 lines (40 loc) · 1.4 KB
/
page__text.xsl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
<?xml version="1.1" encoding="UTF-8"?>
<!--
Author: Philipp Zumstein
License: MIT
-->
<xsl:stylesheet version="2.0"
xmlns="http://schema.primaresearch.org/PAGE/gts/pagecontent/2019-07-15"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text" encoding="utf-8" indent="no" />
<xsl:strip-space elements="*"/>
<xsl:template match="/">
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="*:Unicode">
<xsl:value-of select="current()"/>
</xsl:template>
<xsl:template match="node()">
<!-- Try to to the unicode text as soon as possible and then stop to going deeper in the tree. Otherwise there will be created the same text multiple times. -->
<xsl:choose>
<xsl:when test="./*:Unicode|./*:TextEquiv/*:Unicode">
<xsl:apply-templates select="./*:Unicode|./*:TextEquiv/*:Unicode"/>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates/>
</xsl:otherwise>
</xsl:choose>
<!-- Add space, new line or new page symbol when necessary. -->
<xsl:choose>
<xsl:when test="self::*:TextLine or self::*:TextRegion or self::*:TableRegion">
<xsl:text>
</xsl:text>
</xsl:when>
<xsl:when test="self::*:Word">
<xsl:text> </xsl:text>
</xsl:when>
<xsl:when test="self::*:Page">
<xsl:text></xsl:text>
</xsl:when>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>