-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdir_02_formatTEI.xsl
66 lines (54 loc) · 2.47 KB
/
dir_02_formatTEI.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<?xml version="1.0" encoding="UTF-8"?>
<!-- This script restructures the TEI-formatted file directory, and adds some analysis. -->
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0"
xpath-default-namespace="http://www.tei-c.org/ns/1.0" xmlns="http://www.tei-c.org/ns/1.0">
<xsl:output indent="yes"/>
<!--<xsl:strip-space elements="*"/>-->
<xsl:template match="@*|node()" priority="-1">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="table">
<table>
<!-- This script assumes that all of your xml files are grouped into
subfolders of a single folder named "tei". Update the line below
accordingly (line/column 20:76)-->
<xsl:apply-templates select="row[tokenize(.,'/')[last()-2] eq 'tei']"/>
</table>
</xsl:template>
<!-- Put those variables to work and get some metadata -->
<xsl:template match="row">
<xsl:variable name="full_path" select="cell/text()"/>
<xsl:variable name="file_name">
<xsl:value-of select="replace(tokenize($full_path, '/')[last()], '.xml','')"/>
</xsl:variable>
<xsl:variable name="file" select="document($full_path)"/>
<row>
<!-- Putting the table together is as easy as 1-2-3:
(1) Create a table column by duplicating one of the <cell> elements
below, and give it a name by updating the @select value inside
<xsl:attribute>.
(2) Populate that column's values by updating <xsl:value-of>/@select
with an XPath that queries for something you want to know.
(3) There is no step three!
-->
<cell>
<xsl:attribute name="role" select="'title'"/>
<xsl:value-of select="$file//titleStmt/title"/>
</cell>
<cell>
<xsl:attribute name="role" select="'identifier'"/>
<xsl:value-of select="$file//TEI/@xml:id"/>
</cell>
<cell>
<xsl:attribute name="role" select="'word_count'"/>
<xsl:value-of select="count(/tokenize(normalize-space(string-join($file//text/body//*/text(), ' ')), ' '))"/>
</cell>
<cell>
<xsl:attribute name="role" select="'full_path'"/>
<xsl:value-of select="$full_path"/>
</cell>
</row>
</xsl:template>
</xsl:stylesheet>