-
Notifications
You must be signed in to change notification settings - Fork 2
/
template.xsl
100 lines (86 loc) · 4.45 KB
/
template.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:local="local.uri" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:nex="http://www.nexml.org/2009" xpath-default-namespace="http://www.nexml.org/2009"
version="2.0">
<xsl:strip-space elements="*"/>
<xsl:output method="text"/>
<!-- These variables should not be defined elsewhere
Instead, import this file.-->
<!-- NOTE: $tab may have multiple 	s in it for temporary text readability. Final should have only one-->
<xsl:variable name='tab' select="'	'"/>
<xsl:variable name='line' select="' '"/>
<!-- Location Variables - used in functions without context -->
<xsl:variable name="characters" select="/nexml/characters"/>
<xsl:variable name="trees" select="/nexml/trees"/>
<xsl:variable name="nexml" select="/nexml"/>
<xsl:variable name="root" select="/"/>
<xsl:variable name="otus" select="/nexml/otus"></xsl:variable>
<!-- Variable that selects the file name sans extension of the input XML file -->
<xsl:variable name="filebase">
<xsl:analyze-string select='base-uri()' regex="([/]?)([^/]+)([.])([xml]{{1,}}$)">
<xsl:matching-substring>
<xsl:value-of select="regex-group(2)"/>
</xsl:matching-substring>
</xsl:analyze-string>
</xsl:variable>
<!-- Variable that selects the file name sans extension of the input XML file -->
<xsl:variable name="filefull">
<xsl:analyze-string select='base-uri()' regex="([/]?)([^/]+)([.])([xml]{{1,}}$)">
<xsl:matching-substring>
<xsl:value-of select="regex-group(2)"/>
<xsl:value-of select="regex-group(3)"/>
<xsl:value-of select="regex-group(4)"/>
</xsl:matching-substring>
</xsl:analyze-string>
</xsl:variable>
<!-- Publication variables - Used in Study and Investigation-->
<xsl:variable name="pubid" select="/nexml/meta[@property='tb:identifier.study']/@content"/>
<xsl:variable name="pubtitle" select="/nexml/meta[@property='dc:title']/@content"/>
<xsl:variable name="pubdate" select="/nexml/meta[@property='dc:date']/@content"/>
<xsl:variable name="pubauthors" select="/nexml/meta[@property='dc:creator']/@content"/>
<xsl:variable name="pubdoi" select="/nexml/meta[@property='prism:doi']"/>
<!-- Tree variables - used in I S and A files -->
<xsl:variable name="treetypekinds">
<xsl:for-each select="/nexml/trees/tree">
<xsl:value-of select="./meta[@property='tb:type.tree']/@content"/>
<xsl:text> </xsl:text>
<xsl:value-of select="./meta[@property='tb:kind.tree']/@content"/>
<xsl:value-of select="$tab"/>
</xsl:for-each>
</xsl:variable>
<!-- Functions -->
<!--Todo: make this work when there are no matches & more than one match-->
<xsl:function name="local:matrices-as-rows">
<!-- Takes a matrix and a characters row and returns metadata-->
<!-- note: This must be manually aligned to the column headers -->
<xsl:param name="otus-param"/>
<xsl:param name="characters-param"/>
<xsl:value-of select="local:enquote($characters-param[@otus=$otus-param]/@id)"/>
<xsl:value-of select="local:enquote($characters-param[@otus=$otus-param]/meta[@property='tb:type.matrix']/@content)"/>
<xsl:value-of select="local:empty-cell()"/>
<xsl:value-of select="local:empty-cell()"/>
<xsl:value-of select="local:empty-cell()"/>
</xsl:function>
<xsl:function name="local:enquote">
<!-- Takes input and surrounds each node in quotes and tabs -->
<xsl:param name="node"/>
<xsl:for-each select="$node">
<xsl:text>"</xsl:text>
<xsl:value-of select="."/>
<xsl:text>"</xsl:text>
<xsl:value-of select="$tab"/>
</xsl:for-each>
</xsl:function>
<xsl:function name="local:empty-cell">
<!-- Takes text input and quotes and tabs it. Eqivalent to a tab delimited cell -->
<xsl:param name="text"/>
<xsl:text>"</xsl:text>
<xsl:value-of select="string($text)"/>
<xsl:text>"</xsl:text>
<xsl:value-of select="$tab"/>
</xsl:function>
<xsl:function name="local:empty-cell">
<!-- Zero arity version Eqivalent to a tab delimited cell -->
<xsl:text>""</xsl:text>
<xsl:value-of select="$tab"/>
</xsl:function>
</xsl:stylesheet>