Augmenter: use warnings
[nonametv.git] / tools / de / nonametv-svt-split
blobd5a27a2af0d3b4bd89d2d800965e1df7a47f3d1f
1 #!/bin/sh
3 if [ "x$1" == "x" ]; then
4 echo "nonametv-import-svt <xmlfile>"
5 echo
6 echo "Import a datafile from Svt into the nonametv database."
7 echo
8 exit
9 fi
11 awk 'BEGIN { p=0 } /^</ {p=1} p==1 {print}' $0 | xsltproc - $1
12 exit
13 <?xml version="1.0"?>
14 <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
15 xmlns:exsl="http://exslt.org/common"
16 extension-element-prefixes="exsl"
17 version="1.0">
19 <!--
21 Transform an input file as delivered from Svt into one
22 file per day with the program elements sorted by the
23 start-time of the program. All files are written to
24 the current directory. The program-element is copied
25 unchanged.
27 -->
29 <xsl:output method="xml" indent="yes"/>
31 <xsl:key name="dates" match="program" use="date_utc"/>
32 <xsl:key name="channels" match="program" use="channel"/>
34 <xsl:template match="/">
36 <xsl:if test="count(//program[generate-id() = generate-id(key('channels', channel)[1])]) != 1">
37 <xsl:message terminate="yes">Wrong number of channels</xsl:message>
38 </xsl:if>
40 <xsl:variable name="channel" select="//program[1]/channel/text()"/>
42 <xsl:for-each select="//program[generate-id() = generate-id(key('dates', date_utc)[1])]">
43 <xsl:call-template name="export-date">
44 <xsl:with-param name="date" select="date_utc/text()"/>
45 <xsl:with-param name="channel" select="$channel"/>
46 </xsl:call-template>
47 </xsl:for-each>
48 </xsl:template>
50 <xsl:template name="export-date">
51 <xsl:param name="date"/>
52 <xsl:param name="channel"/>
54 <exsl:document href="{translate($channel, ' ', '-')}_{$date}.xml"
55 method="xml"
56 encoding="iso-8859-1"
57 indent="yes"
58 omit-xml-declaration="no">
59 <programs>
60 <xsl:for-each select="//program[date_utc/text()=$date]">
61 <xsl:sort select="start_time_utc/text()"/>
62 <xsl:copy-of select="."/>
63 </xsl:for-each>
64 </programs>
65 </exsl:document>
66 </xsl:template>
68 </xsl:stylesheet>