diff options
| author | 2017-10-04 21:55:00 -0400 | |
|---|---|---|
| committer | 2017-10-04 21:55:00 -0400 | |
| commit | 61dc07ef400be3613dc4fa395bca161455a402c1 (patch) | |
| tree | 39aed9dafdee33e50387201c79f2f813bd8b5199 /capatomcustom.xsl | |
| download | nwscap-61dc07ef400be3613dc4fa395bca161455a402c1.tar.gz nwscap-61dc07ef400be3613dc4fa395bca161455a402c1.tar.bz2 nwscap-61dc07ef400be3613dc4fa395bca161455a402c1.zip | |
Initial commit of original 2014 code
Diffstat (limited to 'capatomcustom.xsl')
| -rw-r--r-- | capatomcustom.xsl | 446 |
1 files changed, 446 insertions, 0 deletions
diff --git a/capatomcustom.xsl b/capatomcustom.xsl new file mode 100644 index 0000000..b9a5726 --- /dev/null +++ b/capatomcustom.xsl @@ -0,0 +1,446 @@ +<?xml version="1.0" encoding="UTF-8"?> +<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" + xmlns:atom="http://www.w3.org/2005/Atom" + xmlns:cap="urn:oasis:names:tc:emergency:cap:1.1" + xmlns:ha="http://www.alerting.net/namespace/index_1.0" version="1.0"> + + <xsl:import href="dst_check.xsl"/> + + <xsl:output method="html" + indent="yes" + omit-xml-declaration="yes"/> + + + <!-- Feed header --> + <xsl:template match="cap:alert"> + <table width="525" cellspacing="2" cellpadding="0" border="0"> + <tr valign="top"> + <xsl:variable name="lcletters">abcdefghijklmnopqrstuvwxyz</xsl:variable> + <xsl:variable name="ucletters">ABCDEFGHIJKLMNOPQRSTUVWXYZ</xsl:variable> + <xsl:variable name="st"> + <xsl:value-of select="substring(substring-after(cap:identifier/text(),'NOAA-NWS-ALERTS-'),1,2)"/> + </xsl:variable> + <xsl:variable name="lcst"> + <xsl:value-of select="translate(substring(substring-after(cap:identifier/text(),'NOAA-NWS-ALERTS-'),1,2),$ucletters,$lcletters)"/> + </xsl:variable> + + <xsl:variable name="forecastoffice"> + <xsl:value-of select="cap:info/cap:senderName/text()"/> + </xsl:variable> + + <td width="100%" colspan="2"><p><a name="contents" id="contents"></a><a href="http://www.weather.gov/">Home</a> > <a href="http://alerts.weather.gov/">Alerts</a> > + <a border="0"> + <xsl:attribute name="href">http://alerts.weather.gov/cap/<xsl:copy-of select="$lcst"/>.php?x=1</xsl:attribute> + <xsl:choose> + <xsl:when test="contains(cap:note/text(),'(')"> + <xsl:value-of select="substring-before(substring-after(cap:note/text(),'('),')')"/> + </xsl:when> + <xsl:otherwise> + <xsl:copy-of select="$st"/> + </xsl:otherwise> + </xsl:choose> + </a> + > <xsl:value-of select="cap:info/cap:event/text()"/> Issued by <xsl:copy-of select="$forecastoffice"/></p> + <table style="width: 100%; margin-top: 5px; background-color: #e0e0e0; font-family: sans-serif; border: 1px solid black;"> + <tr> + <td style="width: 25px; font-weight: bold; vertical-align: text-top; text-align: right;">Message:</td> + <td> + <xsl:value-of select="cap:identifier/text()"/><span style="text-align: left;"> from </span><xsl:value-of select="cap:sender/text()"/> + </td> + </tr> + <tr> + <td style="width: 25px; font-weight: bold; vertical-align: text-top; text-align: right;">Sent:</td> + <td> + <xsl:value-of select="substring(normalize-space(cap:sent/text()), 12, 5)"/> + <xsl:call-template name="timeZoneName"> + <xsl:with-param name="offset" select="substring(normalize-space(cap:sent/text()), 20, 6)"/> + <xsl:with-param name="year" select="substring(normalize-space(cap:sent/text()), 1, 4)"/> + <xsl:with-param name="month" select="substring(normalize-space(cap:sent/text()), 6, 2)"/> + <xsl:with-param name="day" select="substring(normalize-space(cap:sent/text()), 9, 2)"/> + <xsl:with-param name="st" select="$lcst"/> + </xsl:call-template> + <span style="text-align: left;"> on </span> + <xsl:value-of select="substring(normalize-space(cap:sent/text()), 6, 2)"/>-<xsl:value-of select="substring(normalize-space(cap:sent/text()), 9, 2)"/>-<xsl:value-of select="substring(normalize-space(cap:sent/text()), 1, 4)"/> + </td> + </tr> + <tr> + <td style="width: 25px; font-weight: bold; vertical-align: text-top; text-align: right;">Effective:</td> + <td> + <xsl:value-of select="substring(normalize-space(cap:info/cap:effective/text()), 12, 5)"/> + <xsl:call-template name="timeZoneName"> + <xsl:with-param name="offset" select="substring(normalize-space(cap:info/cap:effective/text()), 20, 6)"/> + <xsl:with-param name="year" select="substring(normalize-space(cap:info/cap:effective/text()), 1, 4)"/> + <xsl:with-param name="month" select="substring(normalize-space(cap:info/cap:effective/text()), 6, 2)"/> + <xsl:with-param name="day" select="substring(normalize-space(cap:info/cap:effective/text()), 9, 2)"/> + <xsl:with-param name="st" select="$lcst"/> + </xsl:call-template> + <span style="text-align: left;"> on </span> + <xsl:value-of select="substring(normalize-space(cap:info/cap:effective/text()), 6, 2)"/>-<xsl:value-of select="substring(normalize-space(cap:info/cap:effective/text()), 9, 2)"/>-<xsl:value-of select="substring(normalize-space(cap:info/cap:effective/text()), 1, 4)"/> + </td> + </tr> + <tr> + <td style="width: 25px; font-weight: bold; vertical-align: text-top; text-align: right;">Expires:</td> + <td> + <xsl:value-of select="substring(normalize-space(cap:info/cap:expires/text()), 12, 5)"/> + <xsl:call-template name="timeZoneName"> + <xsl:with-param name="offset" select="substring(normalize-space(cap:info/cap:expires/text()), 20, 6)"/> + <xsl:with-param name="year" select="substring(normalize-space(cap:info/cap:expires/text()), 1, 4)"/> + <xsl:with-param name="month" select="substring(normalize-space(cap:info/cap:expires/text()), 6, 2)"/> + <xsl:with-param name="day" select="substring(normalize-space(cap:info/cap:expires/text()), 9, 2)"/> + <xsl:with-param name="st" select="$lcst"/> + </xsl:call-template> + <span style="text-align: left;"> on </span> + <xsl:value-of select="substring(normalize-space(cap:info/cap:expires/text()), 6, 2)"/>-<xsl:value-of select="substring(normalize-space(cap:info/cap:expires/text()), 9, 2)"/>-<xsl:value-of select="substring(normalize-space(cap:info/cap:expires/text()), 1, 4)"/> + </td> + </tr> + <tr> + <td colspan="2"> + <table style="background-color: #ffffff; width: 100%; margin-top: 5px; border: 1px solid black;"> + <tr> + <td style="width: 25px; font-weight: bold; vertical-align: text-top; text-align: right;">Event:</td> + <td style="font-size: 1.2em; font-weight: bold;"><xsl:value-of select="cap:info/cap:event/text()"/></td> + </tr> + <tr> + <td style="width: 25px; font-weight: bold; vertical-align: text-top; text-align: right;">Alert:</td> + <td style="font-size: 1.0em;"> + <xsl:variable name="descrip"> + <xsl:call-template name="globalReplace"> + <xsl:with-param name="outputString" select="substring(cap:info/cap:description/text(),1)"/> + <xsl:with-param name="target" select="'
*'"/> + <xsl:with-param name="replacement" select="'

*'"/> + </xsl:call-template> + </xsl:variable> + <xsl:variable name="descrip2"> + <xsl:call-template name="globalReplace"> + <xsl:with-param name="outputString" select="$descrip"/> + <xsl:with-param name="target" select="'
.'"/> + <xsl:with-param name="replacement" select="'

.'"/> + </xsl:call-template> + </xsl:variable> + <xsl:variable name="descrip3"> + <xsl:call-template name="globalReplace"> + <xsl:with-param name="outputString" select="$descrip2"/> + <xsl:with-param name="target" select="'...
THE'"/> + <xsl:with-param name="replacement" select="'...

THE'"/> + </xsl:call-template> + </xsl:variable> + <xsl:variable name="descrip4"> + <xsl:call-template name="globalReplace"> + <xsl:with-param name="outputString" select="$descrip3"/> + <xsl:with-param name="target" select="'...
A'"/> + <xsl:with-param name="replacement" select="'...

A'"/> + </xsl:call-template> + </xsl:variable> + <!-- force a space before newline to facilitate url links --> + <xsl:variable name="descrip5"> + <xsl:call-template name="globalReplace"> + <xsl:with-param name="outputString" select="$descrip4"/> + <xsl:with-param name="target" select="'
'"/> + <xsl:with-param name="replacement" select="' 
'"/> + </xsl:call-template> + </xsl:variable> + <!-- make links hot --> + <xsl:variable name="descrip6"> + <xsl:call-template name="hotlink"> + <xsl:with-param name="text" select="$descrip5"/> + <xsl:with-param name="searchterm1" select="'HTTP'"/> + </xsl:call-template> + </xsl:variable> + <pre style="font-size: 1.0em;"> + <xsl:copy-of select="$descrip6"/> + </pre> + </td> + </tr> + <tr> + <td style="width: 25px; font-weight: bold; vertical-align: text-top; text-align: right;">Instructions:</td> + <td style="font-size: 1.0em;"> + <xsl:value-of select="cap:info/cap:instruction/text()"/> + </td> + </tr> + <tr> + <td style="width: 25px; font-weight: bold; vertical-align: text-top; text-align: right;">Target Area:</td> + <td> + <table style="background-color: #e0e0e0; margin-right: 20px; font-weight: bold;"> + <tr> + <td colspan="2"> + <xsl:variable name="areas1"> + <xsl:call-template name="globalReplace"> + <xsl:with-param name="outputString" select="cap:info/cap:area/cap:areaDesc/text()"/> + <xsl:with-param name="target" select="'/'"/> + <xsl:with-param name="replacement" select="'
'"/> + </xsl:call-template> + </xsl:variable> + <xsl:variable name="areas"> + <xsl:call-template name="globalReplace"> + <xsl:with-param name="outputString" select="$areas1"/> + <xsl:with-param name="target" select="';'"/> + <xsl:with-param name="replacement" select="'
'"/> + </xsl:call-template> + </xsl:variable> + <xsl:variable name="firstchar" select="substring($areas,1,1)"/> + <xsl:choose> + <xsl:when test = "$firstchar = '
'"> <!-- first character is a carriage return --> + <xsl:call-template name="br-replace"> + <xsl:with-param name="text" select="substring($areas,2)"/> + </xsl:call-template> + </xsl:when> + <xsl:otherwise> + <xsl:call-template name="br-replace"> + <xsl:with-param name="text" select="$areas"/> + </xsl:call-template> + </xsl:otherwise> + </xsl:choose> + </td> + </tr> + </table> + </td> + </tr> + </table> + </td> + </tr> + <tr> + <td style="width: 25px; font-weight: bold; vertical-align: text-top; text-align: right;">Forecast Office:</td> + <td><xsl:value-of select="cap:info/cap:senderName/text()"/></td> + </tr> + <tr> + <td colspan="2"> + <table style="background-color: #ffffff; width: 100%; margin-top: 5px; border: 1px solid black;"> + <tr> + <td style="width: 25px; font-weight: bold; vertical-align: text-top; text-align: right;">Raw CAP Message:</td> + <td style="font-size: 0.9em; color: #606060"> + <pre> + <xsl:apply-templates select="/cap:alert" mode="escape"/> + </pre> + </td> + </tr> + </table> + </td> + </tr> + </table> + </td> + </tr> + </table> + <!-- end of main content --> + </xsl:template> + + + <xsl:template match="*" mode="escape"> + <!-- Begin opening tag --> + <xsl:text><</xsl:text> + <xsl:value-of select="name()"/> + + <!-- Attributes --> + <xsl:for-each select="@*"> + <xsl:text> </xsl:text> + <xsl:value-of select="name()"/> + <xsl:text>='</xsl:text> + <xsl:call-template name="escape-xml"> + <xsl:with-param name="text" select="."/> + </xsl:call-template> + <xsl:text>'</xsl:text> + </xsl:for-each> + + <!-- End opening tag --> + <xsl:text>></xsl:text> + + <!-- Content (child elements, text nodes, and PIs) --> + <xsl:apply-templates select="node()" mode="escape" /> + + <!-- Closing tag --> + <xsl:text></</xsl:text> + <xsl:value-of select="name()"/> + <xsl:text>> </xsl:text> + </xsl:template> + + <xsl:template match="text()" mode="escape"> + <xsl:call-template name="escape-xml"> + <xsl:with-param name="text" select="."/> + </xsl:call-template> + </xsl:template> + + <xsl:template match="processing-instruction()" mode="escape"> + <xsl:text><?</xsl:text> + <xsl:value-of select="name()"/> + <xsl:text> </xsl:text> + <xsl:call-template name="escape-xml"> + <xsl:with-param name="text" select="."/> + </xsl:call-template> + <xsl:text>?></xsl:text> + </xsl:template> + + <xsl:template name="escape-xml"> + <xsl:param name="text"/> + <xsl:if test="$text != ''"> + <xsl:variable name="head" select="substring($text, 1, 1)"/> + <xsl:variable name="tail" select="substring($text, 2)"/> + <xsl:choose> + <xsl:when test="$head = '&'">&amp;</xsl:when> + <xsl:when test="$head = '<'">&lt;</xsl:when> + <xsl:when test="$head = '>'">&gt;</xsl:when> + <xsl:when test="$head = '"'">&quot;</xsl:when> + <xsl:when test="$head = "'"">&apos;</xsl:when> + <xsl:otherwise><xsl:value-of select="$head"/></xsl:otherwise> + </xsl:choose> + <xsl:call-template name="escape-xml"> + <xsl:with-param name="text" select="$tail"/> + </xsl:call-template> + </xsl:if> + </xsl:template> + + <!-- Time Zone function --> + <xsl:template name="timeZoneName"> + <xsl:param name="offset"/> + <xsl:param name="year"/> + <xsl:param name="month"/> + <xsl:param name="day"/> + <xsl:param name="st"/> + + <!-- determine if its DST or not, based on run time --> + <xsl:variable name="dst_start"> + <xsl:call-template name="day-light-savings-start"> + <xsl:with-param name="year" select="$year"/> + </xsl:call-template> + </xsl:variable> + + <xsl:variable name="dst_end"> + <xsl:call-template name="day-light-savings-end"> + <xsl:with-param name="year" select="$year"/> + </xsl:call-template> + </xsl:variable> + + <xsl:variable name="tod_jul"> + <xsl:call-template name="date-to-absolute-day"> + <xsl:with-param name="year" select="$year"/> + <xsl:with-param name="month" select="$month"/> + <xsl:with-param name="day" select="$day"/> + </xsl:call-template> + </xsl:variable> + + <xsl:variable name="dst_flag"> + <xsl:choose> + <xsl:when test="$dst_start <= $tod_jul and $dst_end >= $tod_jul">dst</xsl:when> + <xsl:otherwise>nodst</xsl:otherwise> + </xsl:choose> + </xsl:variable> + + <xsl:if test="$offset = '+10:00'"> <xsl:text> ChST</xsl:text> </xsl:if> + <xsl:if test="$offset = '-11:00'"> <xsl:text> SST</xsl:text> </xsl:if> + <xsl:if test="$offset = '-10:00'"> <xsl:text> HST</xsl:text> </xsl:if> + <xsl:if test="$offset = '-00:00'"> <xsl:text> GMT</xsl:text> </xsl:if> + <xsl:if test="$offset = '+00:00'"> <xsl:text> GMT</xsl:text> </xsl:if> + + <xsl:choose> + <xsl:when test="$dst_flag = 'nodst'"> + <xsl:if test="$offset = '-09:00'"> <xsl:text> AKST</xsl:text> </xsl:if> + <xsl:if test="$offset = '-08:00'"> <xsl:text> PST</xsl:text> </xsl:if> + <xsl:if test="$offset = '-07:00'"> <xsl:text> MST</xsl:text> </xsl:if> + <xsl:if test="$offset = '-06:00'"> <xsl:text> CST</xsl:text> </xsl:if> + <xsl:if test="$offset = '-05:00'"> <xsl:text> EST</xsl:text> </xsl:if> + <xsl:if test="$offset = '-04:00'"> <xsl:text> AST</xsl:text> </xsl:if> + </xsl:when> + <xsl:otherwise> + <xsl:choose> + <xsl:when test="$st = 'az'"> + <xsl:if test="$offset = '-08:00'"> <xsl:text> PST</xsl:text> </xsl:if> + <xsl:if test="$offset = '-07:00'"> <xsl:text> MST</xsl:text> </xsl:if> + <xsl:if test="$offset = '-06:00'"> <xsl:text> CST</xsl:text> </xsl:if> + </xsl:when> + <xsl:otherwise> + <xsl:if test="$offset = '-08:00'"> <xsl:text> AKDT</xsl:text> </xsl:if> + <xsl:if test="$offset = '-07:00'"> <xsl:text> PDT</xsl:text> </xsl:if> + <xsl:if test="$offset = '-06:00'"> <xsl:text> MDT</xsl:text> </xsl:if> + <xsl:if test="$offset = '-05:00'"> <xsl:text> CDT</xsl:text> </xsl:if> + <xsl:if test="$offset = '-04:00'"> <xsl:text> EDT</xsl:text> </xsl:if> + <xsl:if test="$offset = '-03:00'"> <xsl:text> ADT</xsl:text> </xsl:if> + </xsl:otherwise> + </xsl:choose> + </xsl:otherwise> + </xsl:choose> + + </xsl:template> + + <!-- Replace function --> + <xsl:template name="globalReplace"> + <xsl:param name="outputString"/> + <xsl:param name="target"/> + <xsl:param name="replacement"/> + <xsl:choose> + <xsl:when test="contains($outputString,$target)"> + + <xsl:value-of select= + "concat(substring-before($outputString,$target),$replacement)"/> + <xsl:call-template name="globalReplace"> + <xsl:with-param name="outputString" select="substring-after($outputString,$target)"/> + <xsl:with-param name="target" select="$target"/> + <xsl:with-param name="replacement" select="$replacement"/> + </xsl:call-template> + </xsl:when> + <xsl:otherwise> + <xsl:value-of select="$outputString"/> + </xsl:otherwise> + </xsl:choose> + </xsl:template> + + <!-- Replace new lines with html <br> tags --> + <xsl:template name="br-replace"> + <xsl:param name="text"/> + <xsl:variable name="cr" select="'
'"/> + <xsl:choose> + <!-- If the value of the $text parameter contains carriage ret --> + <xsl:when test="contains($text,$cr)"> + <!-- Return the substring of $text before the carriage return --> + <xsl:value-of select="substring-before($text,$cr)"/> + <!-- And construct a <br/> element --> + <br/> + <!-- + | Then invoke this same br-replace template again, passing the + | substring *after* the carriage return as the new "$text" to + | consider for replacement + +--> + <xsl:call-template name="br-replace"> + <xsl:with-param name="text" select="substring-after($text,$cr)"/> + </xsl:call-template> + </xsl:when> + <xsl:otherwise> + <xsl:value-of select="$text"/> + </xsl:otherwise> + </xsl:choose> + </xsl:template> + + <!-- If it looks like a link, make it hot --> + <xsl:template name="hotlink"> + <xsl:param name="text"/> + <xsl:param name="searchterm1"/> + + <xsl:variable name="lcletters">abcdefghijklmnopqrstuvwxyz</xsl:variable> + <xsl:variable name="ucletters">ABCDEFGHIJKLMNOPQRSTUVWXYZ</xsl:variable> + + <xsl:choose> + <xsl:when test="contains($text,$searchterm1)"> + + <!-- grab data before the searchterm --> + <xsl:value-of select="substring-before($text,$searchterm1)"/> + <a border="0"> + <xsl:attribute name="href"> + <!-- determine actual link by taking data from the searchterm to + either the space or the newline - whichever is first --> + <xsl:value-of select="translate(concat($searchterm1,substring-before(substring-after($text,$searchterm1),' ')),$ucletters,$lcletters)"/> + </xsl:attribute> + <xsl:value-of select="translate(concat($searchterm1,substring-before(substring-after($text,$searchterm1),' ')),$ucletters,$lcletters)"/> </a> + + <!-- data after the link - check for more links --> + <xsl:call-template name="hotlink"> + <xsl:with-param name="text" select="substring-after(substring-after($text,$searchterm1),' ')"/> + <xsl:with-param name="searchterm1" select="$searchterm1"/> + </xsl:call-template> + </xsl:when> + <xsl:otherwise> + <xsl:value-of select="$text"/> + </xsl:otherwise> + </xsl:choose> + </xsl:template> + + <!-- Ignore anything else --> + <xsl:template match="*"></xsl:template> + +</xsl:stylesheet> |