Statistics
| Revision:

root / tmp / org.txm.core / res / org / txm / xml / xsl / txm-front-teiHeader2textAtt.xsl @ 187

History | View | Annotate | Download (5.8 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:tei="http://www.tei-c.org/ns/1.0"
4
  exclude-result-prefixes="tei edate" xpath-default-namespace="http://www.tei-c.org/ns/1.0" version="2.0">
5

    
6
  <!--
7
This software is dual-licensed:
8

    
9
1. Distributed under a Creative Commons Attribution-ShareAlike 3.0
10
Unported License http://creativecommons.org/licenses/by-sa/3.0/ 
11

    
12
2. http://www.opensource.org/licenses/BSD-2-Clause
13
		
14
All rights reserved.
15

    
16
Redistribution and use in source and binary forms, with or without
17
modification, are permitted provided that the following conditions are
18
met:
19

    
20
* Redistributions of source code must retain the above copyright
21
notice, this list of conditions and the following disclaimer.
22

    
23
* Redistributions in binary form must reproduce the above copyright
24
notice, this list of conditions and the following disclaimer in the
25
documentation and/or other materials provided with the distribution.
26

    
27
This software is provided by the copyright holders and contributors
28
"as is" and any express or implied warranties, including, but not
29
limited to, the implied warranties of merchantability and fitness for
30
a particular purpose are disclaimed. In no event shall the copyright
31
holder or contributors be liable for any direct, indirect, incidental,
32
special, exemplary, or consequential damages (including, but not
33
limited to, procurement of substitute goods or services; loss of use,
34
data, or profits; or business interruption) however caused and on any
35
theory of liability, whether in contract, strict liability, or tort
36
(including negligence or otherwise) arising in any way out of the use
37
of this software, even if advised of the possibility of such damage.
38

    
39
     
40
This stylesheet extracts metadata from the teiHeader and adds them as attributes
41
of the text element. Can be used with TXM XTZ and XML/W import modules.
42

    
43
Written by Alexei Lavrentiev, UMR 5317 IHRIM, 2017
44
  -->
45

    
46

    
47
  <xsl:output method="xml" encoding="utf-8" omit-xml-declaration="no"/> 
48
  
49
  
50
<!-- General patterns: all elements, attributes, comments and processing instructions are copied -->
51
  
52
  <xsl:template match="*">      
53
        <xsl:copy>
54
          <xsl:apply-templates select="*|@*|processing-instruction()|comment()|text()"/>
55
        </xsl:copy>    
56
  </xsl:template>
57
  
58
  <xsl:template match="*" mode="position"><xsl:value-of select="count(preceding-sibling::*)"/></xsl:template>
59

    
60
  <xsl:template match="@*|comment()|processing-instruction()">
61
    <xsl:copy/>
62
  </xsl:template>
63

    
64
  <xsl:variable name="current-file-name">
65
    <xsl:analyze-string select="document-uri(.)" regex="^(.*)/([^/]+)\.[^/]+$">
66
      <xsl:matching-substring>
67
        <xsl:value-of select="regex-group(2)"/>
68
      </xsl:matching-substring>
69
    </xsl:analyze-string>
70
  </xsl:variable>
71
  
72
<!-- Extracting metadata to use -->
73
 
74
  <xsl:variable name="title">
75
    <xsl:choose>
76
      <xsl:when test="/TEI/teiHeader/fileDesc/titleStmt/title[@type='main']">
77
        <xsl:value-of select="/TEI/teiHeader/fileDesc/titleStmt/title[@type='main'][1]"/>
78
      </xsl:when>
79
      <xsl:otherwise>
80
        <xsl:value-of select="/TEI/teiHeader/fileDesc/titleStmt/title[1]"/>
81
      </xsl:otherwise>
82
    </xsl:choose>
83
  </xsl:variable>
84
  
85
  <xsl:variable name="author">
86
    <xsl:choose>
87
      <xsl:when test="/TEI/teiHeader/fileDesc/titleStmt/author">
88
        <xsl:for-each select="/TEI/teiHeader/fileDesc/titleStmt/author">
89
          <xsl:value-of select="."/>
90
          <xsl:if test="following-sibling::author">
91
            <xsl:text>, </xsl:text>
92
          </xsl:if>
93
        </xsl:for-each>
94
      </xsl:when>
95
      <xsl:otherwise>
96
        <xsl:text>anonyme</xsl:text>
97
      </xsl:otherwise>
98
    </xsl:choose>
99
  </xsl:variable>
100
  
101
  <xsl:variable name="text_creation_date">
102
    <xsl:choose>
103
      <xsl:when test="/TEI/teiHeader/profileDesc/creation/date[@type='compo']">
104
        <xsl:choose>
105
          <xsl:when test="/TEI/teiHeader/profileDesc/creation/date[@type='compo'][1]/@when">
106
            <xsl:value-of select="/TEI/teiHeader/profileDesc/creation/date[@type='compo'][1]/@when"/>
107
          </xsl:when>
108
          <xsl:otherwise>
109
            <xsl:value-of select="/TEI/teiHeader/profileDesc/creation/date[@type='compo'][1]"/>
110
          </xsl:otherwise>
111
        </xsl:choose>
112
      </xsl:when>
113
      <xsl:when test="/TEI/teiHeader/profileDesc/creation/date">
114
        <xsl:choose>
115
          <xsl:when test="/TEI/teiHeader/profileDesc/creation/date[1]/@when">
116
            <xsl:value-of select="/TEI/teiHeader/profileDesc/creation/date[1]/@when"/>
117
          </xsl:when>
118
          <xsl:otherwise>
119
            <xsl:value-of select="/TEI/teiHeader/profileDesc/creation/date[1]"/>
120
          </xsl:otherwise>
121
        </xsl:choose>
122
      </xsl:when>
123
      <xsl:otherwise>
124
        <xsl:text>sans date</xsl:text>
125
      </xsl:otherwise>
126
    </xsl:choose>
127
  </xsl:variable>
128
  
129
  <xsl:variable name="genre">
130
    <xsl:choose>
131
      <xsl:when test="/TEI/teiHeader//keywords/term[@type='genre']">
132
        <xsl:value-of select="/TEI/teiHeader//keywords[1]/term[@type='genre'][1]"/>
133
      </xsl:when>
134
      <xsl:otherwise>
135
        <xsl:text>inconnu</xsl:text>
136
      </xsl:otherwise>
137
    </xsl:choose>
138
  </xsl:variable>
139

    
140
<!-- Injecting metadata into attibutes of the text element -->
141

    
142
<xsl:template match="text">
143
  <xsl:copy>
144
    <xsl:apply-templates select="@*"/>
145
    <xsl:attribute name="id"><xsl:value-of select="$current-file-name"/></xsl:attribute>
146
    <xsl:attribute name="titre"><xsl:value-of select="$title"/></xsl:attribute>
147
    <xsl:attribute name="auteur"><xsl:value-of select="$author"/></xsl:attribute>
148
    <xsl:attribute name="date-compo"><xsl:value-of select="$text_creation_date"/></xsl:attribute>
149
    <xsl:attribute name="genre"><xsl:value-of select="$genre"/></xsl:attribute>
150
    <xsl:apply-templates/>
151
  </xsl:copy>
152
</xsl:template>
153

    
154

    
155
</xsl:stylesheet>