File: text_html.xsl

package info (click to toggle)
libgo-perl 0.15-10
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 8,112 kB
  • sloc: perl: 13,147; sh: 21; makefile: 7
file content (132 lines) | stat: -rw-r--r-- 3,976 bytes parent folder | download | duplicates (7)
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
<?xml version = "1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output method="html"/>

    <xsl:key name="is-as" match="term" use="is_a"/>
    <xsl:key name="part-ofs" match="term" use="relationship/to"/>
    <xsl:key name="terms" match="term" use="id"/>

    <xsl:template match="/">
	<xsl:element name="html">
		<xsl:element name="body">
			<xsl:element name="link">
				<xsl:attribute name="href">ontology_html.css</xsl:attribute>
				<xsl:attribute name="rel">stylesheet</xsl:attribute>
				<xsl:attribute name="type">text/css</xsl:attribute>
			</xsl:element>

<xsl:element name="pre">!type: % is_a is a
!type: &lt; part_of Part of</xsl:element>
			<xsl:apply-templates mode="first" select="obo/term[1]"/>
		</xsl:element>
	</xsl:element>
    </xsl:template>


    <xsl:template match="term" mode="first">
	<ul class="first">
		<li class="first">
			<xsl:text>$</xsl:text>
		        <xsl:value-of select="name"/>
			<xsl:text> ; </xsl:text>
			<xsl:value-of select="id"/>
			<xsl:variable name="current_id" select="id"/> 
			<xsl:apply-templates
				mode="not-first"
				select="key('part-ofs', id)">
				<xsl:with-param name="rel_type">part-of</xsl:with-param>
			</xsl:apply-templates>
			<xsl:apply-templates
				mode="not-first"
				select="key('is-as', id)">
				<xsl:with-param name="rel_type">is_a</xsl:with-param>
			</xsl:apply-templates>
		</li>
	</ul>
    </xsl:template>

    <xsl:template match="term" mode="not-first">
	<xsl:param name="parent_id"><xsl:value-of select="/obo/term[1]/id"/></xsl:param>
	<xsl:param name="rel_type"/>
	<ul>
		<li>
			<xsl:choose>
				<xsl:when test="$rel_type = 'part-of'">
					<xsl:text>%</xsl:text>
				</xsl:when>
				<xsl:when test="$rel_type = 'is_a'">
					<xsl:text>&lt;</xsl:text>
				</xsl:when>
			</xsl:choose>
			<xsl:apply-templates 
				select="."
				mode="term">
				<xsl:with-param name="parent_id"><xsl:value-of select="$parent_id"/></xsl:with-param>
			</xsl:apply-templates>
			<xsl:apply-templates
				mode="not-first"
				select="key('is-as', id)">
				<xsl:with-param name="parent_id"><xsl:value-of select="id"/></xsl:with-param>
				<xsl:with-param name="rel_type">part-of</xsl:with-param>
			</xsl:apply-templates>
			<xsl:apply-templates
				mode="not-first"
				select="key('part-ofs', id)">
				<xsl:with-param name="parent_id"><xsl:value-of select="id"/></xsl:with-param>
				<xsl:with-param name="rel_type">part-of</xsl:with-param>
			</xsl:apply-templates>
		</li>
	</ul>
    </xsl:template>

   <xsl:template match="term" name="term" mode="term">
	<xsl:param name="parent_id"><xsl:value-of select="/obo/term[1]/id"/></xsl:param>
		        <xsl:element name="a">
				<xsl:attribute name="id">
					<xsl:value-of select="id"/>
				</xsl:attribute>
				<xsl:value-of select="name"/>
				<xsl:text> ; </xsl:text>
				<xsl:value-of select="id"/>
			</xsl:element>	
			<xsl:apply-templates select="synonym"/>
			<xsl:apply-templates mode="parents" select="relationship[to != $parent_id]"/>
			<xsl:apply-templates mode="parents" select="is_a[text() != $parent_id]"/>
    </xsl:template>
 
    <xsl:template match="relationship" mode="parents">
	<xsl:text> &lt; </xsl:text>
	<xsl:apply-templates
				mode="draw-parent"
				select="key('terms', to)"/>
	<xsl:value-of select="to"/>
    </xsl:template>

    <xsl:template match="is_a" mode="parents">
	<xsl:text> % </xsl:text>
	<xsl:apply-templates
				mode="draw-parent"
				select="key('terms', .)"/>
	<xsl:value-of select="."/>
    </xsl:template>

    <xsl:template match="term" mode="draw-parent">
	<xsl:element name="a">
		<xsl:attribute name="href">#<xsl:value-of select="id"/></xsl:attribute>
		<xsl:value-of select="name"/>
	</xsl:element>
	<xsl:text> ; </xsl:text>
    </xsl:template>	

    <xsl:template match="synonym">
	<xsl:text> ; synonym:</xsl:text>
	<xsl:value-of select="synonym_text"/>
    </xsl:template>

   <xsl:template match="text()|@*">
    </xsl:template>

</xsl:stylesheet>