Statistics
| Revision:

root / tmp / org.txm.core / res / org / txm / xml / xsl / txm-filter-teitextgrid-xmlw-posttok.xsl @ 187

History | View | Annotate | Download (5.3 kB)

1
<?xml version="1.0"?>
2
<xsl:stylesheet xmlns:edate="http://exslt.org/dates-and-times"
3
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xd="http://www.pnp-software.com/XSLTdoc" xmlns:tei="http://www.tei-c.org/ns/1.0" xmlns:txm="http://textometrie.org/1.0"
4
  exclude-result-prefixes="tei edate txm" xpath-default-namespace="http://www.tei-c.org/ns/1.0" version="2.0">
5

    
6
  <xd:doc type="stylesheet">
7
    <xd:short>
8
      This stylesheet is used on tokenized DARIAH-DE TextGrid files
9
      in the TXM XML/w + csv import process.
10
    </xd:short>
11
    <xd:detail>
12
      This stylesheet is free software; you can redistribute it and/or
13
      modify it under the terms of the GNU Lesser General Public
14
      License as published by the Free Software Foundation; either
15
      version 3 of the License, or (at your option) any later version.
16
      
17
      This stylesheet is distributed in the hope that it will be useful,
18
      but WITHOUT ANY WARRANTY; without even the implied warranty of
19
      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
20
      Lesser General Public License for more details.
21
      
22
      You should have received a copy of GNU Lesser Public License with
23
      this stylesheet. If not, see http://www.gnu.org/licenses/lgpl.html
24
    </xd:detail>
25
    <xd:author>Alexei Lavrentiev alexei.lavrentev@ens-lyon.fr</xd:author>
26
    <xd:copyright>2014, CNRS / ICAR (CACTUS)</xd:copyright>
27
  </xd:doc>
28
  
29

    
30
  <xsl:output method="xml" encoding="utf-8" omit-xml-declaration="no"/> 
31

    
32
  <!-- By default, copy all attributes, comments, processing instructions and text nodes -->
33

    
34
  <xsl:template match="@*|comment()|processing-instruction()">
35
    <xsl:copy/>
36
  </xsl:template>
37
  
38
  <xsl:template match="text()">
39
    <xsl:value-of select="."/>
40
  </xsl:template>
41
  
42
  <!-- delete the teiHeader for xml/w import module-->
43
  
44
  <xsl:template match="teiHeader"/>
45
  
46
  
47
<!-- The page breaks must be placed before the structural units (text divions) that 
48
    start on a given page (to avoid empty elements creation when splitting the pages of the
49
    TXM edition) -->
50

    
51
  <xsl:template match="text">
52
    <xsl:copy>
53
      <xsl:apply-templates select="@*"/>
54
      <xsl:if test="not(child::*[1][self::pb])"><pb xmlns="http://www.tei-c.org/ns/1.0" n="title"/></xsl:if>
55
      <xsl:apply-templates/>
56
    </xsl:copy>
57
  </xsl:template>  
58

    
59
  <xsl:template match="*">    
60
    <xsl:if test="descendant::tei:pb and (parent::tei:text or preceding-sibling::*)">
61
      <!-- on déplace les pb initiaux avant la balise de l'élément le plus haut -->
62
      <xsl:call-template name="raisePb"/>
63
    </xsl:if>
64
    <xsl:choose>
65
      <xsl:when test="namespace-uri()=''">
66
        <xsl:element namespace="http://www.tei-c.org/ns/1.0" name="{local-name(.)}">
67
          <xsl:apply-templates select="*|@*|processing-instruction()|comment()|text()"/>
68
        </xsl:element>
69
      </xsl:when>
70
      <xsl:otherwise>
71
        <xsl:copy>
72
          <xsl:apply-templates select="*|@*|processing-instruction()|comment()|text()"/>
73
        </xsl:copy>
74
      </xsl:otherwise>
75
    </xsl:choose>  
76
  </xsl:template>
77
  
78
  <xsl:template match="tei:pb[not(preceding-sibling::*) and not(parent::tei:text)]">
79
    <xsl:comment>Pb déplacé plus haut</xsl:comment>
80
  </xsl:template>
81
  
82
  <xsl:template name="raisePb">
83
    <xsl:if test="descendant::tei:pb">
84
      <xsl:for-each select="child::*[1][descendant-or-self::tei:pb]">
85
        <xsl:choose>
86
          <xsl:when test="self::tei:pb"><xsl:comment>Pb remonté</xsl:comment>
87
            <xsl:copy>
88
              <xsl:apply-templates select="@*"/>
89
              <xsl:if test="not(@n) and not(@facs) and following-sibling::tei:fw[1 or 2][@type='pageNum']">
90
                <xsl:attribute name="n"><xsl:value-of select="normalize-space(following-sibling::tei:fw[@type='pageNum'][1])"/></xsl:attribute>
91
              </xsl:if>
92
            </xsl:copy></xsl:when>
93
          <xsl:otherwise><xsl:call-template name="raisePb"></xsl:call-template></xsl:otherwise>
94
        </xsl:choose>
95
      </xsl:for-each>
96
    </xsl:if>
97
  </xsl:template>
98
  
99
  
100
<!-- add @ref to words (for concordances) -->
101

    
102
  <xsl:variable name="filename">
103
    <xsl:analyze-string select="document-uri(.)" regex="^(.*)/([^/]+)\.[^/]+$">
104
      <xsl:matching-substring>
105
        <xsl:value-of select="regex-group(2)"/>
106
      </xsl:matching-substring>
107
    </xsl:analyze-string>
108
  </xsl:variable>
109
  
110
  <xsl:template match="w">
111
    <xsl:variable name="ref">
112
      <xsl:choose>
113
        <xsl:when test="preceding::pb[1][@n]">
114
          <xsl:value-of select="concat($filename,', p. ',preceding::pb[1]/@n)"/>
115
        </xsl:when>
116
        <xsl:otherwise><xsl:value-of select="$filename"/></xsl:otherwise>
117
      </xsl:choose>
118
    </xsl:variable>
119
        <w xmlns="http://www.tei-c.org/ns/1.0" ref="{$ref}">
120
          <xsl:apply-templates select="@*"/>
121
          <xsl:apply-templates select="*|processing-instruction()|comment()|text()"/>
122
        </w>
123
  </xsl:template>
124

    
125
<!-- transform speaker into an attribute of the sp element -->
126

    
127
  <xsl:template match="sp">
128
    <xsl:copy>
129
      <xsl:if test="child::speaker">
130
        <xsl:variable name="who">
131
          <xsl:value-of select="speaker"/>
132
        </xsl:variable>
133
        <xsl:attribute name="who"><xsl:value-of select="normalize-space(replace($who,'\s*\p{P}+\s*$',''))"/></xsl:attribute>
134
        <xsl:apply-templates/>
135
      </xsl:if>
136
    </xsl:copy>
137
  </xsl:template>
138
  
139
  <xsl:template match="speaker"/>
140
  
141

    
142
</xsl:stylesheet>