-
Notifications
You must be signed in to change notification settings - Fork 4
/
page-textequiv-words-to-lines.xsl
42 lines (42 loc) · 2.05 KB
/
page-textequiv-words-to-lines.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
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:pc="http://schema.primaresearch.org/PAGE/gts/pagecontent/2019-07-15" xmlns:exslt="http://exslt.org/common" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.0" extension-element-prefixes="exslt">
<xsl:output omit-xml-declaration="no" indent="yes" method="xml" encoding="utf-8"/>
<!-- recalculate each TextLine text content by concatenating from its Word entries
(but only if the TextLine does contain Words)
ignore non-first TextEquivs, intersperse with space characters -->
<xsl:template match="//pc:TextLine[pc:Word]/pc:TextEquiv[1]/pc:Unicode/text()" name="concatenate">
<xsl:param name="context" select="../../.."/>
<xsl:for-each select="$context/pc:Word">
<xsl:copy-of select="pc:TextEquiv[1]/pc:Unicode/text()"/>
<xsl:if test="not(position()=last())">
<xsl:text> </xsl:text>
</xsl:if>
</xsl:for-each>
</xsl:template>
<!-- if a TextLine does not have a TextEquiv yet
create it, and call the concatenation by name
-->
<xsl:template match="//pc:TextLine[pc:Word and not(pc:TextEquiv)]">
<xsl:copy>
<!-- keep correct order (attributes, elements before TextEquiv, elements after TextEquiv -->
<xsl:apply-templates select="@*|node()[local-name()!='TextStyle' and local-name()!='UserDefined' and local-name()!='Labels']"/>
<xsl:if test="not(pc:TextEquiv)">
<xsl:element name="pc:TextEquiv">
<xsl:element name="pc:Unicode">
<xsl:call-template name="concatenate">
<xsl:with-param name="context" select="."/>
</xsl:call-template>
</xsl:element>
</xsl:element>
</xsl:if>
<xsl:apply-templates select="pc:TextStyle"/>
<xsl:apply-templates select="pc:UserDefined"/>
<xsl:apply-templates select="pc:Labels"/>
</xsl:copy>
</xsl:template>
<xsl:template match="@*|node()" name="identity">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>