Fix line endings

This commit is contained in:
Lucidiot 2021-03-19 13:50:29 +01:00
parent 6750898bf2
commit ccc54dbbe4
Signed by: lucidiot
GPG Key ID: 3358C1CA6906FB8D
2 changed files with 397 additions and 393 deletions

View File

@ -1,201 +1,201 @@
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:itsb="http://tilde.town/~lucidiot/itsb/">
<xsl:output method="html" />
<xsl:variable name="lowercase" select="'abcdefghijklmnopqrstuvwxyz'" />
<xsl:variable name="uppercase" select="'ABCDEFGHIJKLMNOPQRSTUVWXYZ'" />
<xsl:key name="feedKey" match="itsb:feed" use="concat(../@id, ' ', @lang, ' ', @type)" />
<xsl:template match="/">
<html>
<head>
<title>international transport safety bureau</title>
<link rel="stylesheet" type="text/css" href="../theme.css" />
<link rel="shortcut icon" type="image/x-icon" href="../img/favicon.ico"/>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="author" content="~lucidiot" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
</head>
<body class="container" id="top">
<div class="centered">
<img src="img/itsb.gif" alt="itsb logo: an antenna receives an alert from an airplane" />
<h1>international transport safety bureau</h1>
<p>
<xsl:for-each select="//itsb:section">
<a href="{concat('#', @id)}">
<xsl:value-of select="@name" />
</a>
<xsl:if test="position() != last()">
<xsl:text> &#8212; </xsl:text>
</xsl:if>
</xsl:for-each>
</p>
</div>
<xsl:apply-templates />
</body>
</html>
</xsl:template>
<xsl:template match="itsb:section">
<div class="section" id="{@id}">
<a href="#top" class="toplink">back to top</a>
<h2>
<xsl:value-of select="@name" />
</h2>
<xsl:apply-templates />
</div>
</xsl:template>
<xsl:template match="itsb:content">
<xsl:value-of select="text()" disable-output-escaping="yes" />
</xsl:template>
<xsl:template match="itsb:source">
<h3 id="{@id}">
<xsl:value-of select="itsb:name/text()" />
</h3>
<xsl:apply-templates select="itsb:description" />
<table>
<tbody>
<xsl:apply-templates select="itsb:region | itsb:type | itsb:frequency | itsb:license" />
<xsl:choose>
<xsl:when test="count(itsb:feed[generate-id(.) = generate-id(key('feedKey', concat(../@id, ' ', @lang, ' ', @type)))]) = 1">
<tr>
<td>
<strong>Language</strong>
</td>
<td>
<xsl:value-of select="itsb:feed/@lang" />
</td>
</tr>
<tr>
<td>
<strong>Feed</strong>
</td>
<td>
<xsl:apply-templates select="itsb:feed">
<xsl:sort select="@format" />
</xsl:apply-templates>
</td>
</tr>
</xsl:when>
<xsl:otherwise>
<tr>
<td>
<strong>Feeds</strong>
</td>
<td>
<table>
<tbody>
<xsl:for-each select="itsb:feed[generate-id(.) = generate-id(key('feedKey', concat(../@id, ' ', @lang, ' ', @type)))]">
<xsl:sort select="@lang" />
<xsl:sort select="@type" />
<xsl:variable name="lang" select="@lang" />
<xsl:variable name="type" select="@type" />
<tr>
<td>
<xsl:value-of select="concat(translate(substring($lang, 1, 1), $lowercase, $uppercase), substring($lang, 2))" />
<xsl:if test="$lang and $type">
<xsl:text>, </xsl:text>
</xsl:if>
<xsl:value-of select="concat(translate(substring($type, 1, 1), $lowercase, $uppercase), substring($type, 2))" />
</td>
<td>
<xsl:apply-templates select="../itsb:feed[(@lang = $lang or (not(@lang) and not ($lang))) and (@type = $type or (not(@type) and not($type)))]">
<xsl:sort select="@format" />
</xsl:apply-templates>
</td>
</tr>
</xsl:for-each>
</tbody>
</table>
</td>
</tr>
</xsl:otherwise>
</xsl:choose>
</tbody>
</table>
</xsl:template>
<xsl:template match="itsb:description">
<xsl:value-of select="text()" disable-output-escaping="yes" />
</xsl:template>
<xsl:template match="itsb:region">
<tr>
<td>
<strong>Region</strong>
</td>
<td>
<xsl:value-of select="text()" />
</td>
</tr>
</xsl:template>
<xsl:template match="itsb:type">
<tr>
<td>
<strong>Types</strong>
</td>
<td>
<xsl:value-of select="text()" />
</td>
</tr>
</xsl:template>
<xsl:template match="itsb:frequency">
<tr>
<td>
<strong>Frequency</strong>
</td>
<td>
<xsl:value-of select="text()" />
</td>
</tr>
</xsl:template>
<xsl:template match="itsb:license">
<tr>
<td>
<strong>License</strong>
</td>
<td>
<xsl:choose>
<xsl:when test="@url">
<a href="{@url}" target="_blank">
<xsl:value-of select="text()" />
</a>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="text()" />
</xsl:otherwise>
</xsl:choose>
</td>
</tr>
</xsl:template>
<xsl:template match="itsb:feed">
<xsl:variable name="href">
<xsl:choose>
<xsl:when test="itsb:link">
<xsl:value-of select="itsb:link/text()" />
</xsl:when>
<xsl:otherwise>
<xsl:text>feeds/</xsl:text>
<xsl:value-of select="itsb:output/text()" />
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<a href="{$href}" target="_blank">
<img src="img/{@format}.gif" alt="{@format}" />
</a>
<xsl:text> </xsl:text>
</xsl:template>
</xsl:stylesheet>
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:itsb="http://tilde.town/~lucidiot/itsb/">
<xsl:output method="html" />
<xsl:variable name="lowercase" select="'abcdefghijklmnopqrstuvwxyz'" />
<xsl:variable name="uppercase" select="'ABCDEFGHIJKLMNOPQRSTUVWXYZ'" />
<xsl:key name="feedKey" match="itsb:feed" use="concat(../@id, ' ', @lang, ' ', @type)" />
<xsl:template match="/">
<html>
<head>
<title>international transport safety bureau</title>
<link rel="stylesheet" type="text/css" href="../theme.css" />
<link rel="shortcut icon" type="image/x-icon" href="../img/favicon.ico"/>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="author" content="~lucidiot" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
</head>
<body class="container" id="top">
<div class="centered">
<img src="img/itsb.gif" alt="itsb logo: an antenna receives an alert from an airplane" />
<h1>international transport safety bureau</h1>
<p>
<xsl:for-each select="//itsb:section">
<a href="{concat('#', @id)}">
<xsl:value-of select="@name" />
</a>
<xsl:if test="position() != last()">
<xsl:text> &#8212; </xsl:text>
</xsl:if>
</xsl:for-each>
</p>
</div>
<xsl:apply-templates />
</body>
</html>
</xsl:template>
<xsl:template match="itsb:section">
<div class="section" id="{@id}">
<a href="#top" class="toplink">back to top</a>
<h2>
<xsl:value-of select="@name" />
</h2>
<xsl:apply-templates />
</div>
</xsl:template>
<xsl:template match="itsb:content">
<xsl:value-of select="text()" disable-output-escaping="yes" />
</xsl:template>
<xsl:template match="itsb:source">
<h3 id="{@id}">
<xsl:value-of select="itsb:name/text()" />
</h3>
<xsl:apply-templates select="itsb:description" />
<table>
<tbody>
<xsl:apply-templates select="itsb:region | itsb:type | itsb:frequency | itsb:license" />
<xsl:choose>
<xsl:when test="count(itsb:feed[generate-id(.) = generate-id(key('feedKey', concat(../@id, ' ', @lang, ' ', @type)))]) = 1">
<tr>
<td>
<strong>Language</strong>
</td>
<td>
<xsl:value-of select="itsb:feed/@lang" />
</td>
</tr>
<tr>
<td>
<strong>Feed</strong>
</td>
<td>
<xsl:apply-templates select="itsb:feed">
<xsl:sort select="@format" />
</xsl:apply-templates>
</td>
</tr>
</xsl:when>
<xsl:otherwise>
<tr>
<td>
<strong>Feeds</strong>
</td>
<td>
<table>
<tbody>
<xsl:for-each select="itsb:feed[generate-id(.) = generate-id(key('feedKey', concat(../@id, ' ', @lang, ' ', @type)))]">
<xsl:sort select="@lang" />
<xsl:sort select="@type" />
<xsl:variable name="lang" select="@lang" />
<xsl:variable name="type" select="@type" />
<tr>
<td>
<xsl:value-of select="concat(translate(substring($lang, 1, 1), $lowercase, $uppercase), substring($lang, 2))" />
<xsl:if test="$lang and $type">
<xsl:text>, </xsl:text>
</xsl:if>
<xsl:value-of select="concat(translate(substring($type, 1, 1), $lowercase, $uppercase), substring($type, 2))" />
</td>
<td>
<xsl:apply-templates select="../itsb:feed[(@lang = $lang or (not(@lang) and not ($lang))) and (@type = $type or (not(@type) and not($type)))]">
<xsl:sort select="@format" />
</xsl:apply-templates>
</td>
</tr>
</xsl:for-each>
</tbody>
</table>
</td>
</tr>
</xsl:otherwise>
</xsl:choose>
</tbody>
</table>
</xsl:template>
<xsl:template match="itsb:description">
<xsl:value-of select="text()" disable-output-escaping="yes" />
</xsl:template>
<xsl:template match="itsb:region">
<tr>
<td>
<strong>Region</strong>
</td>
<td>
<xsl:value-of select="text()" />
</td>
</tr>
</xsl:template>
<xsl:template match="itsb:type">
<tr>
<td>
<strong>Types</strong>
</td>
<td>
<xsl:value-of select="text()" />
</td>
</tr>
</xsl:template>
<xsl:template match="itsb:frequency">
<tr>
<td>
<strong>Frequency</strong>
</td>
<td>
<xsl:value-of select="text()" />
</td>
</tr>
</xsl:template>
<xsl:template match="itsb:license">
<tr>
<td>
<strong>License</strong>
</td>
<td>
<xsl:choose>
<xsl:when test="@url">
<a href="{@url}" target="_blank">
<xsl:value-of select="text()" />
</a>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="text()" />
</xsl:otherwise>
</xsl:choose>
</td>
</tr>
</xsl:template>
<xsl:template match="itsb:feed">
<xsl:variable name="href">
<xsl:choose>
<xsl:when test="itsb:link">
<xsl:value-of select="itsb:link/text()" />
</xsl:when>
<xsl:otherwise>
<xsl:text>feeds/</xsl:text>
<xsl:value-of select="itsb:output/text()" />
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<a href="{$href}" target="_blank">
<img src="img/{@format}.gif" alt="{@format}" />
</a>
<xsl:text> </xsl:text>
</xsl:template>
</xsl:stylesheet>

View File

@ -1,192 +1,196 @@
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns="http://tilde.town/~lucidiot/itsb/"
xmlns:itsb="http://tilde.town/~lucidiot/itsb/">
<xsl:output method="xml" />
<!-- Preprocesses the itsb.xml file to autocomplete with converted feeds. -->
<!-- Caution: Final slash is required. -->
<xsl:variable name="itsbRoot" select="'https://tilde.town/~lucidiot/itsb/'" />
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*" />
</xsl:copy>
</xsl:template>
<xsl:template match="itsb:feed">
<xsl:copy-of select="." />
<!-- Store attributes in variables to make them accessible in conditionals later on -->
<xsl:variable name="lang" select="@lang" />
<xsl:variable name="type" select="@type" />
<!-- This is an Atom feed and there is no RSS feed: add a conversion -->
<xsl:choose>
<xsl:when test="@format = 'atom' and not(../itsb:feed[((not(@lang) and not($lang)) or @lang = $lang) and ((not(@type) and not($type)) or @type = $type) and (@format = 'rss' or @format = 'rdf')])">
<feed format="rss">
<xsl:if test="@lang">
<xsl:attribute name="lang">
<xsl:value-of select="@lang" />
</xsl:attribute>
</xsl:if>
<xsl:if test="@type">
<xsl:attribute name="type">
<xsl:value-of select="@type" />
</xsl:attribute>
</xsl:if>
<xsl:attribute name="id">
<xsl:value-of select="@id" />
<xsl:text>-rss</xsl:text>
</xsl:attribute>
<xsl:choose>
<xsl:when test="itsb:output">
<shell>
<xsl:text>cat $DIR/feeds/</xsl:text>
<xsl:value-of select="itsb:output/text()" />
</shell>
</xsl:when>
<xsl:otherwise>
<curl>
<url>
<xsl:value-of select="itsb:link/text()" />
</url>
</curl>
</xsl:otherwise>
</xsl:choose>
<xml2json />
<jq path="convert/atom2rss.jq" />
<json2xml />
<output>
<xsl:text>_rss/</xsl:text>
<xsl:choose>
<xsl:when test="itsb:output">
<xsl:value-of select="itsb:output/text()" />
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="@id" />
<xsl:text>.xml</xsl:text>
</xsl:otherwise>
</xsl:choose>
</output>
</feed>
<!-- Perform all the other conversions -->
<xsl:call-template name="convertall" />
</xsl:when>
<xsl:when test="@format = 'rss'">
<xsl:call-template name="convertall" />
</xsl:when>
</xsl:choose>
</xsl:template>
<xsl:template name="convertall">
<xsl:call-template name="converter">
<xsl:with-param name="format" select="'json'" />
<xsl:with-param name="extension" select="'json'" />
</xsl:call-template>
<xsl:call-template name="converter">
<xsl:with-param name="format" select="'cdf'" />
<xsl:with-param name="extension" select="'cdf'" />
</xsl:call-template>
<xsl:call-template name="converter">
<xsl:with-param name="format" select="'echo'" />
<xsl:with-param name="extension" select="'xml'" />
</xsl:call-template>
</xsl:template>
<xsl:template name="converter">
<xsl:param name="format" />
<xsl:param name="extension" />
<feed format="{$format}">
<xsl:if test="@lang">
<xsl:attribute name="lang">
<xsl:value-of select="@lang" />
</xsl:attribute>
</xsl:if>
<xsl:if test="@type">
<xsl:attribute name="type">
<xsl:value-of select="@type" />
</xsl:attribute>
</xsl:if>
<xsl:attribute name="id">
<xsl:value-of select="@id" />
<xsl:text>-</xsl:text>
<xsl:value-of select="$format" />
</xsl:attribute>
<xsl:choose>
<xsl:when test="itsb:output">
<shell>
<xsl:text>cat $DIR/feeds/</xsl:text>
<xsl:choose>
<xsl:when test="@format = 'atom' and $format != 'json'">
<xsl:text>_rss/</xsl:text>
<xsl:value-of select="@id" />
<xsl:text>.xml</xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="itsb:output/text()" />
</xsl:otherwise>
</xsl:choose>
</shell>
</xsl:when>
<xsl:otherwise>
<curl>
<url>
<xsl:value-of select="itsb:link/text()" />
</url>
</curl>
</xsl:otherwise>
</xsl:choose>
<xml2json />
<jq>
<xsl:attribute name="path">
<xsl:text>convert/</xsl:text>
<xsl:choose>
<xsl:when test="$format = 'json'">
<xsl:value-of select="@format" />
<xsl:text>2jsonfeed.jq</xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:text>rss2</xsl:text>
<xsl:value-of select="$format" />
<xsl:text>.jq</xsl:text>
</xsl:otherwise>
</xsl:choose>
</xsl:attribute>
<xsl:if test="$format = 'json'">
<arg name="feed_url">
<xsl:value-of select="$itsbRoot" />
<xsl:text>feeds/_json/</xsl:text>
<xsl:value-of select="@id" />
<xsl:text>.json</xsl:text>
</arg>
</xsl:if>
</jq>
<xsl:if test="$format != 'json'">
<json2xml short-empty="true" />
</xsl:if>
<output>
<xsl:text>_</xsl:text>
<xsl:value-of select="$format" />
<xsl:text>/</xsl:text>
<xsl:value-of select="@id" />
<xsl:text>.</xsl:text>
<xsl:value-of select="$extension" />
</output>
</feed>
</xsl:template>
</xsl:stylesheet>
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns="http://tilde.town/~lucidiot/itsb/"
xmlns:itsb="http://tilde.town/~lucidiot/itsb/">
<xsl:output method="xml" />
<!-- Preprocesses the itsb.xml file to autocomplete with converted feeds. -->
<!-- Caution: Final slash is required. -->
<xsl:variable name="itsbRoot" select="'https://tilde.town/~lucidiot/itsb/'" />
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*" />
</xsl:copy>
</xsl:template>
<xsl:template match="itsb:feed">
<xsl:copy-of select="." />
<!-- Store attributes in variables to make them accessible in conditionals later on -->
<xsl:variable name="lang" select="@lang" />
<xsl:variable name="type" select="@type" />
<!-- This is an Atom feed and there is no RSS feed: add a conversion -->
<xsl:choose>
<xsl:when test="@format = 'atom' and not(../itsb:feed[((not(@lang) and not($lang)) or @lang = $lang) and ((not(@type) and not($type)) or @type = $type) and (@format = 'rss' or @format = 'rdf')])">
<feed format="rss">
<xsl:if test="@lang">
<xsl:attribute name="lang">
<xsl:value-of select="@lang" />
</xsl:attribute>
</xsl:if>
<xsl:if test="@type">
<xsl:attribute name="type">
<xsl:value-of select="@type" />
</xsl:attribute>
</xsl:if>
<xsl:attribute name="id">
<xsl:value-of select="@id" />
<xsl:text>-rss</xsl:text>
</xsl:attribute>
<xsl:choose>
<xsl:when test="itsb:output">
<shell>
<xsl:text>cat $DIR/feeds/</xsl:text>
<xsl:value-of select="itsb:output/text()" />
</shell>
</xsl:when>
<xsl:otherwise>
<curl>
<url>
<xsl:value-of select="itsb:link/text()" />
</url>
<!-- Some official feeds do not work with curl's user agent -->
<header name="User-Agent">ITSB/1.0</header>
</curl>
</xsl:otherwise>
</xsl:choose>
<xml2json />
<jq path="convert/atom2rss.jq" />
<json2xml />
<output>
<xsl:text>_rss/</xsl:text>
<xsl:choose>
<xsl:when test="itsb:output">
<xsl:value-of select="itsb:output/text()" />
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="@id" />
<xsl:text>.xml</xsl:text>
</xsl:otherwise>
</xsl:choose>
</output>
</feed>
<!-- Perform all the other conversions -->
<xsl:call-template name="convertall" />
</xsl:when>
<xsl:when test="@format = 'rss'">
<xsl:call-template name="convertall" />
</xsl:when>
</xsl:choose>
</xsl:template>
<xsl:template name="convertall">
<xsl:call-template name="converter">
<xsl:with-param name="format" select="'json'" />
<xsl:with-param name="extension" select="'json'" />
</xsl:call-template>
<xsl:call-template name="converter">
<xsl:with-param name="format" select="'cdf'" />
<xsl:with-param name="extension" select="'cdf'" />
</xsl:call-template>
<xsl:call-template name="converter">
<xsl:with-param name="format" select="'echo'" />
<xsl:with-param name="extension" select="'xml'" />
</xsl:call-template>
</xsl:template>
<xsl:template name="converter">
<xsl:param name="format" />
<xsl:param name="extension" />
<feed format="{$format}">
<xsl:if test="@lang">
<xsl:attribute name="lang">
<xsl:value-of select="@lang" />
</xsl:attribute>
</xsl:if>
<xsl:if test="@type">
<xsl:attribute name="type">
<xsl:value-of select="@type" />
</xsl:attribute>
</xsl:if>
<xsl:attribute name="id">
<xsl:value-of select="@id" />
<xsl:text>-</xsl:text>
<xsl:value-of select="$format" />
</xsl:attribute>
<xsl:choose>
<xsl:when test="itsb:output">
<shell>
<xsl:text>cat $DIR/feeds/</xsl:text>
<xsl:choose>
<xsl:when test="@format = 'atom' and $format != 'json'">
<xsl:text>_rss/</xsl:text>
<xsl:value-of select="@id" />
<xsl:text>.xml</xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="itsb:output/text()" />
</xsl:otherwise>
</xsl:choose>
</shell>
</xsl:when>
<xsl:otherwise>
<curl>
<url>
<xsl:value-of select="itsb:link/text()" />
</url>
<!-- Some official feeds do not work with curl's user agent -->
<header name="User-Agent">ITSB/1.0</header>
</curl>
</xsl:otherwise>
</xsl:choose>
<xml2json />
<jq>
<xsl:attribute name="path">
<xsl:text>convert/</xsl:text>
<xsl:choose>
<xsl:when test="$format = 'json'">
<xsl:value-of select="@format" />
<xsl:text>2jsonfeed.jq</xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:text>rss2</xsl:text>
<xsl:value-of select="$format" />
<xsl:text>.jq</xsl:text>
</xsl:otherwise>
</xsl:choose>
</xsl:attribute>
<xsl:if test="$format = 'json'">
<arg name="feed_url">
<xsl:value-of select="$itsbRoot" />
<xsl:text>feeds/_json/</xsl:text>
<xsl:value-of select="@id" />
<xsl:text>.json</xsl:text>
</arg>
</xsl:if>
</jq>
<xsl:if test="$format != 'json'">
<json2xml short-empty="true" />
</xsl:if>
<output>
<xsl:text>_</xsl:text>
<xsl:value-of select="$format" />
<xsl:text>/</xsl:text>
<xsl:value-of select="@id" />
<xsl:text>.</xsl:text>
<xsl:value-of select="$extension" />
</output>
</feed>
</xsl:template>
</xsl:stylesheet>