-
Notifications
You must be signed in to change notification settings - Fork 2
/
news.xsl
215 lines (162 loc) · 6.95 KB
/
news.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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE xsl:stylesheet>
<!--*
* Create the news page
*-->
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:str="http://exslt.org/strings"
xmlns:date="http://exslt.org/dates-and-times"
xmlns:func="http://exslt.org/functions"
xmlns:exsl="http://exslt.org/common"
xmlns:extfuncs="http://hea-www.harvard.edu/~dburke/xsl/extfuncs"
extension-element-prefixes="date str func exsl extfuncs">
<!--* Change this if the filename changes *-->
<xsl:variable name="hack-import-news" select="extfuncs:register-import-dependency('news.xsl')"/>
<xsl:output method="text"/>
<!--* a template to output a new line (useful after a comment) *-->
<xsl:template name="newline">
<xsl:text>
</xsl:text>
</xsl:template>
<!--* load in the set of "global" parameters *-->
<xsl:include href="globalparams.xsl"/>
<!--* include the stylesheets AFTER defining the variables *-->
<xsl:include href="helper.xsl"/>
<xsl:include href="links.xsl"/>
<xsl:include href="myhtml.xsl"/>
<!--*
* top level: create
* news.html
*
*-->
<xsl:template match="/">
<!--* check the params are okay *-->
<xsl:call-template name="is-site-valid"/>
<xsl:call-template name="check-param-ends-in-a-slash">
<xsl:with-param name="pname" select="'install'"/>
<xsl:with-param name="pvalue" select="$install"/>
</xsl:call-template>
<xsl:call-template name="check-param-ends-in-a-slash">
<xsl:with-param name="pname" select="'canonicalbase'"/>
<xsl:with-param name="pvalue" select="$canonicalbase"/>
</xsl:call-template>
<!--* what do we create *-->
<xsl:apply-templates select="news" mode="main"/>
<xsl:apply-templates select="news" mode="feed"/>
</xsl:template> <!--* match=/ *-->
<!--*
* create: news.html
*-->
<xsl:template match="news" mode="main">
<xsl:variable name="filename"><xsl:value-of select="$install"/><xsl:value-of select="$pagename"/>.html</xsl:variable>
<!--* output filename to stdout *-->
<xsl:value-of select="$filename"/><xsl:call-template name="newline"/>
<!--* create document *-->
<xsl:document href="{$filename}" method="html" media-type="text/html"
doctype-system="about:legacy-compat"
version="5.0">
<!--* we start processing the XML file here *-->
<html lang="en-US">
<!--* make the HTML head node *-->
<xsl:call-template name="add-htmlhead-standard"/>
<xsl:call-template name="add-contents"/>
</html>
</xsl:document>
</xsl:template> <!--* match=news *-->
<xsl:template name="add-contents">
<xsl:call-template name="add-body-withnavbar">
<xsl:with-param name="contents">
<h1 class="pagetitle">What's New for CIAO <xsl:value-of select="$siteversion"/></h1>
<p class="feed"><a href="http://cxc.harvard.edu/ciao/feed.xml">Subscribe to the CIAO News RSS feed</a></p>
<hr/>
<xsl:apply-templates select="//text/item" mode="main"/>
</xsl:with-param>
<xsl:with-param name="navbar">
<xsl:call-template name="add-navbar">
<xsl:with-param name="name" select="info/navbar"/>
</xsl:call-template>
</xsl:with-param>
</xsl:call-template>
</xsl:template>
<xsl:template match="news" mode="feed">
<xsl:variable name="filename"><xsl:value-of select="$install"/>feed.xml</xsl:variable>
<!--* create document *-->
<xsl:document href="{$filename}">
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/">
<channel><xsl:call-template name="newline"/>
<title>CIAO Software News</title><xsl:call-template name="newline"/>
<link>http://cxc.harvard.edu/ciao/news.html</link><xsl:call-template name="newline"/>
<description>What's New in the CIAO Software</description><xsl:call-template name="newline"/>
<atom:link xmlns:atom="http://www.w3.org/2005/Atom" href="http://cxc.harvard.edu/ciao/feed.xml" rel="self" type="application/rss+xml" />
<xsl:apply-templates select="//text/item" mode="feed"/>
</channel>
</rss>
</xsl:document>
</xsl:template> <!--* match=news *-->
<!--* note: we process the text so we can handle our `helper' tags *-->
<xsl:template match="text">
<xsl:apply-templates/>
</xsl:template> <!--* text *-->
<!-- news items template / HTML -->
<xsl:template match="item" mode="main">
<xsl:for-each select=".">
<!-- create summary and id -->
<div class="newsitem">
<h3>
<xsl:attribute name="id">
<xsl:text>item-</xsl:text>
<xsl:value-of select="pubdate"/>
</xsl:attribute>
<xsl:value-of select="title"/>
</h3>
<p class="newsdate"><xsl:call-template name="calculate-pubdate-html"/></p>
<div>
<xsl:apply-templates select="desc/*"/>
</div>
</div>
</xsl:for-each>
</xsl:template>
<!-- end main bug content template -->
<!-- news items template / feed -->
<xsl:template match="item" mode="feed">
<xsl:for-each select=".">
<item>
<title><xsl:value-of select="title"/></title>
<pubDate><xsl:call-template name="calculate-pubdate-feed"/></pubDate>
<link><xsl:value-of select="$outurl"/><xsl:text>news.html#item-</xsl:text><xsl:value-of select="pubdate"/></link>
<guid><xsl:value-of select="$outurl"/><xsl:text>news.html#item-</xsl:text><xsl:value-of select="pubdate"/></guid>
<description>
<xsl:text disable-output-escaping="yes"><![CDATA[</xsl:text>
<xsl:apply-templates select="desc/*"/>
<xsl:text disable-output-escaping="yes">]]</xsl:text>
<xsl:text disable-output-escaping="yes">></xsl:text>
</description>
</item>
</xsl:for-each>
</xsl:template>
<!-- end feed bug content template -->
<xsl:template name="calculate-pubdate-html">
<xsl:variable name="daynum" select="date:day-in-month(pubdate)"/>
<xsl:variable name="month" select="substring(date:month-name(pubdate),1,3)"/>
<xsl:variable name="year" select="date:year(pubdate)"/>
<xsl:if test="number($year)<2010">
<xsl:message terminate="yes">
Error: year is set to '<xsl:value-of select="$year"/>';
must be 2010 or later
</xsl:message>
</xsl:if>
<xsl:value-of select="concat($daynum,' ',$month,' ',$year)"/>
</xsl:template>
<xsl:template name="calculate-pubdate-feed">
<xsl:variable name="dayname" select="substring(date:day-name(pubdate),1,3)"/>
<xsl:variable name="dayn" select="date:day-in-month(pubdate)"/>
<xsl:variable name="daynum"><xsl:choose>
<xsl:when test="number($dayn)>9"><xsl:value-of select="$dayn"></xsl:value-of></xsl:when>
<xsl:otherwise><xsl:value-of select="concat('0',$dayn)"></xsl:value-of></xsl:otherwise>
</xsl:choose></xsl:variable>
<xsl:variable name="month" select="substring(date:month-name(pubdate),1,3)"/>
<xsl:variable name="year" select="date:year(pubdate)"/>
<xsl:value-of select="concat($dayname,', ',$daynum,' ',$month,' ',$year,' 00:00 EST')"/>
</xsl:template>
</xsl:stylesheet>