forked from tdengg/elements
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinputtohtml.xsl
158 lines (135 loc) · 4.5 KB
/
inputtohtml.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
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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<head>
<title>
<xsl:value-of select="//title" />
</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.min.js"/>
<script src="http://static.exciting-code.org/Jmol.js" />
</head>
<body>
<table border="0">
<tr>
<td>
<h2>
<xsl:value-of select="//title" />
</h2>
<script>
<xsl:text>
jmolInitialize("http://jmol.sourceforge.net/jmol");
jmolCheckBrowser("popup", "http://jmol.sourceforge.net/browsercheck", "onClick");
function trim(str, chars) {
return ltrim(rtrim(str, chars), chars);
}
function ltrim(str, chars) {
chars = chars || "\\s";
return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}
function rtrim(str, chars) {
chars = chars || "\\s";
return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}
function transformlaticecoordxyz(coordstring){
var basevect=new Array(3);
var tmp;
var sep= new RegExp(" +");
</xsl:text>
<xsl:for-each select="//basevect">
<xsl:text>tmp="</xsl:text>
<xsl:value-of select="." />
<xsl:text>";
</xsl:text>
<xsl:text>basevect[</xsl:text>
<xsl:value-of select="position()-1" />
<xsl:text>]=new Array(3);
</xsl:text>
<xsl:text>basevect[</xsl:text>
<xsl:value-of select="position()-1" />
<xsl:text>]=trim(tmp).split(sep);
</xsl:text>
</xsl:for-each>
<xsl:text>
var coord=trim(coordstring).split(sep);
var output = new Array(3);
output[0]=(coord[0] * basevect[0][0] + coord[1] * basevect[0][1]+ coord[2] * basevect[0][2])*0.529177249;
output[1]=(coord[0] * basevect[1][0] + coord[1] * basevect[1][1] + coord[2] * basevect[1][2])*0.529177249;
output[2]=(coord[0] * basevect[2][0] + coord[1] * basevect[2][1] + coord[2] * basevect[2][2])*0.529177249;
return output.join(" ");
}
var structure="</xsl:text>
<xsl:value-of select="count(//atom)" />
<xsl:text>";
structure=structure+"|testing|";
</xsl:text>
<xsl:for-each select="//species">
<xsl:variable name="symbol">
<xsl:choose>
<xsl:when test="@chemicalSymbol">
<xsl:value-of select="@chemicalSymbol" />
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="'X'" />
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:for-each select="atom">
<xsl:text>structure=structure+"</xsl:text>
<xsl:value-of select="$symbol" />
<xsl:text> "+transformlaticecoordxyz("</xsl:text>
<xsl:value-of select="@coord" />
<xsl:text>")+"|";
</xsl:text>
</xsl:for-each>
</xsl:for-each>
<xsl:text>
jmolAppletInline(400, structure, "background white;", "");
</xsl:text>
</script>
</td>
</tr>
<xsl:for-each
select="/input/*[name()!='structure' and name()!='title']">
<tr>
<td>
<xsl:call-template name="attributestotable" />
</td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
<xsl:template name="attributestotable">
<h2>
<xsl:value-of select="name(.)" />
</h2>
<table>
<xsl:for-each select="@*">
<tr>
<td>
<xsl:element name="a">
<xsl:attribute name="href">
http://exciting-code.org/input-reference#<xsl:value-of
select="name(.)" />
</xsl:attribute>
<xsl:value-of select="name(.)" />
</xsl:element>
</td>
<td>
<xsl:value-of select="." />
</td>
</tr>
</xsl:for-each>
<xsl:for-each select="*">
<tr>
<td>
<xsl:call-template name="attributestotable" />
</td>
</tr>
</xsl:for-each>
</table>
</xsl:template>
</xsl:stylesheet>