]> Wikimedia Canada | Git repositories - eccc_to_commons.git/commitdiff
Add transformation to fix ECCC XML files
authorPierre Choffet <peuc@wanadoo.fr>
Wed, 23 Oct 2019 23:52:16 +0000 (19:52 -0400)
committerPierre Choffet <peuc@wanadoo.fr>
Mon, 23 Dec 2019 22:19:50 +0000 (17:19 -0500)
The monthly files are provided with an error on the root element. The eccc_fixer.xslt fixes it so it can be validated before processing.

commons_rules.xsd [new file with mode: 0644]
eccc_fixer.xslt [new file with mode: 0644]

diff --git a/commons_rules.xsd b/commons_rules.xsd
new file mode 100644 (file)
index 0000000..1bfd00d
--- /dev/null
@@ -0,0 +1,962 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- This schema is required to validate Environment and Climate Change Canada
+     historical data prior of its import into Wikidata.
+
+     All tests done in ECCC's bulkschema.xsd aren't replicated here as we're
+     focusing into pure Wikimedia Commons data quality -->
+<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
+       <!-- Define elements -->
+       <xsd:element name="climatedata">
+               <xsd:complexType>
+                       <xsd:sequence>
+                               <xsd:element ref="lang" minOccurs="1" maxOccurs="1" />
+                               <xsd:element ref="stationinformation" minOccurs="1" maxOccurs="1" />
+                               <xsd:element ref="legend" minOccurs="1" maxOccurs="1" />
+                               <xsd:element ref="stationdata" minOccurs="1" maxOccurs="unbounded" />
+                       </xsd:sequence>
+               </xsd:complexType>
+       </xsd:element>
+
+       <xsd:element name="lang">
+               <xsd:simpleType>
+                       <xsd:restriction base="xsd:string">
+                               <xsd:annotation>
+                                       <xsd:documentation xml:lang="en">For consistency reasons in names and numeric formats, we enforce import of English files in Commons.
+                                       </xsd:documentation>
+                               </xsd:annotation>
+                               <xsd:enumeration value="ENG" />
+                       </xsd:restriction>
+               </xsd:simpleType>
+       </xsd:element>
+
+       <xsd:element name="stationinformation">
+               <xsd:complexType>
+                       <xsd:sequence>
+                               <xsd:element ref="name" minOccurs="1" maxOccurs="1" />
+                               <xsd:element ref="province" minOccurs="1" maxOccurs="1" />
+                               <xsd:element ref="stationoperator" minOccurs="0" maxOccurs="1" />
+                               <xsd:element ref="latitude" minOccurs="1" maxOccurs="1" />
+                               <xsd:element ref="longitude" minOccurs="1" maxOccurs="1" />
+                               <xsd:element ref="elevation" minOccurs="1" maxOccurs="1" />
+                               <xsd:element ref="climate_identifier" minOccurs="1" maxOccurs="1" />
+                               <xsd:element ref="wmo_identifier" minOccurs="1" maxOccurs="1" />
+                               <xsd:element ref="tc_identifier" minOccurs="1" maxOccurs="1" />
+                       </xsd:sequence>
+               </xsd:complexType>
+       </xsd:element>
+
+       <xsd:element name="name">
+               <xsd:simpleType>
+                       <xsd:restriction base="xsd:string">
+                               <xsd:pattern value="[0-9A-Z '().#,\-/&amp;]+" />
+                       </xsd:restriction>
+               </xsd:simpleType>
+       </xsd:element>
+
+       <xsd:element name="province">
+               <xsd:simpleType>
+                       <xsd:restriction base="xsd:string">
+                               <xsd:enumeration value="ALBERTA" />
+                               <xsd:enumeration value="BRITISH COLUMBIA" />
+                               <xsd:enumeration value="QUEBEC" />
+                               <xsd:enumeration value="MANITOBA" />
+                               <xsd:enumeration value="NEW BRUNSWICK" />
+                               <xsd:enumeration value="NEWFOUNDLAND" />
+                               <xsd:enumeration value="NORTHWEST TERRITORIES" />
+                               <xsd:enumeration value="NOVA SCOTIA" />
+                               <xsd:enumeration value="NUNAVUT" />
+                               <xsd:enumeration value="ONTARIO" />
+                               <xsd:enumeration value="PRINCE EDWARD ISLAND" />
+                               <xsd:enumeration value="SASKATCHEWAN" />
+                               <xsd:enumeration value="YUKON TERRITORY" />
+                       </xsd:restriction>
+               </xsd:simpleType>
+       </xsd:element>
+
+       <xsd:element name="stationoperator">
+               <xsd:simpleType>
+                       <xsd:restriction base="xsd:string">
+                               <xsd:pattern value="[A-Za-z -]+" />
+                       </xsd:restriction>
+               </xsd:simpleType>
+       </xsd:element>
+
+       <xsd:element name="latitude">
+               <xsd:simpleType>
+                       <xsd:union memberTypes="zero">
+                               <xsd:annotation>
+                                       <xsd:documentation xml:lang="en">WARNING: latitude can be zero
+                                       </xsd:documentation>
+                               </xsd:annotation>
+                               <xsd:simpleType>
+                                       <xsd:restriction base="xsd:float">
+                                               <xsd:minInclusive value="41.6" />
+                                               <xsd:maxInclusive value="83.2" />
+                                       </xsd:restriction>
+                               </xsd:simpleType>
+                               <xsd:simpleType>
+                                       <xsd:annotation>
+                                               <xsd:documentation xml:lang="en">WARNING: en_climate_monthly_NB_8104200_1872-1952_P1M.xml is in Russia
+                                               </xsd:documentation>
+                                       </xsd:annotation>
+                                       <xsd:restriction base="xsd:float">
+                                               <xsd:enumeration value="45.07" />
+                                       </xsd:restriction>
+                               </xsd:simpleType>
+                       </xsd:union>
+               </xsd:simpleType>
+       </xsd:element>
+
+       <xsd:element name="longitude">
+               <xsd:simpleType>
+                       <xsd:union memberTypes="zero">
+                               <xsd:annotation>
+                                       <xsd:documentation xml:lang="en">WARNING: longitude can be zero
+                                       </xsd:documentation>
+                               </xsd:annotation>
+                               <xsd:simpleType>
+                                       <xsd:restriction base="xsd:float">
+                                               <xsd:minInclusive value="-141.0" />
+                                               <xsd:maxInclusive value="-52.0" />
+                                       </xsd:restriction>
+                               </xsd:simpleType>
+                               <xsd:simpleType>
+                                       <xsd:annotation>
+                                               <xsd:documentation xml:lang="en">WARNING: en_climate_monthly_NB_8104200_1872-1952_P1M.xml is in Russia
+                                               </xsd:documentation>
+                                       </xsd:annotation>
+                                       <xsd:restriction base="xsd:float">
+                                               <xsd:enumeration value="66.47" />
+                                       </xsd:restriction>
+                               </xsd:simpleType>
+                       </xsd:union>
+               </xsd:simpleType>
+       </xsd:element>
+
+       <xsd:element name="elevation">
+               <xsd:simpleType>
+                       <xsd:union memberTypes="empty">
+                               <xsd:simpleType>
+                                       <xsd:restriction base="xsd:float">
+                                               <xsd:minInclusive value="0.0" />
+                                               <xsd:maxInclusive value="2926.1" />
+                                       </xsd:restriction>
+                               </xsd:simpleType>
+                       </xsd:union>
+               </xsd:simpleType>
+       </xsd:element>
+
+       <xsd:element name="climate_identifier">
+               <xsd:simpleType>
+                       <xsd:restriction base="xsd:string">
+                               <xsd:pattern value="[0-9A-Z]+" />
+                       </xsd:restriction>
+               </xsd:simpleType>
+       </xsd:element>
+
+       <xsd:element name="wmo_identifier">
+               <xsd:simpleType>
+                       <xsd:union memberTypes="empty">
+                               <xsd:simpleType>
+                                       <xsd:restriction base="xsd:nonNegativeInteger" />
+                               </xsd:simpleType>
+                       </xsd:union>
+               </xsd:simpleType>
+       </xsd:element>
+
+       <xsd:element name="tc_identifier">
+               <xsd:simpleType>
+                       <xsd:union memberTypes="empty">
+                               <xsd:simpleType>
+                                       <xsd:restriction base="xsd:string">
+                                               <xsd:pattern value="[A-Z0-9]{3}" />
+                                       </xsd:restriction>
+                               </xsd:simpleType>
+                       </xsd:union>
+               </xsd:simpleType>
+       </xsd:element>
+
+       <xsd:element name="legend">
+               <xsd:complexType>
+                       <xsd:sequence>
+                               <xsd:element ref="flag" minOccurs="1" maxOccurs="unbounded" />
+                       </xsd:sequence>
+               </xsd:complexType>
+       </xsd:element>
+
+       <xsd:element name="flag">
+               <xsd:complexType>
+                       <xsd:sequence>
+                               <xsd:element ref="symbol" minOccurs="1" maxOccurs="1" />
+                               <xsd:element ref="description" minOccurs="1" maxOccurs="1" />
+                       </xsd:sequence>
+               </xsd:complexType>
+       </xsd:element>
+
+       <xsd:element name="symbol">
+               <xsd:simpleType>
+                       <xsd:union>
+                               <xsd:simpleType>
+                                       <xsd:restriction base="xsd:string">
+                                               <xsd:length value="1" />
+                                       </xsd:restriction>
+                               </xsd:simpleType>
+                               <xsd:simpleType>
+                                       <xsd:restriction base="xsd:string">
+                                               <xsd:enumeration value="[empty]">
+                                                       <xsd:annotation>
+                                                               <xsd:documentation xml:lang="en">[empty] is an allowed value
+                                                               </xsd:documentation>
+                                                       </xsd:annotation>
+                                               </xsd:enumeration>
+                                       </xsd:restriction>
+                               </xsd:simpleType>
+                       </xsd:union>
+               </xsd:simpleType>
+       </xsd:element>
+
+       <xsd:element name="description" type="xsd:anyType" />
+
+       <xsd:element name="stationdata">
+               <xsd:complexType>
+                       <xsd:sequence>
+                               <xsd:element ref="meanmaxtemp" minOccurs="1" maxOccurs="1" />
+                               <xsd:element ref="meanmintemp" minOccurs="1" maxOccurs="1" />
+                               <xsd:element ref="meanmonthtemp" minOccurs="1" maxOccurs="1" />
+                               <xsd:element ref="extrmaxtemp" minOccurs="1" maxOccurs="1" />
+                               <xsd:element ref="extrmintemp" minOccurs="1" maxOccurs="1" />
+                               <xsd:element ref="totrain" minOccurs="1" maxOccurs="1" />
+                               <xsd:element ref="totsnow" minOccurs="1" maxOccurs="1" />
+                               <xsd:element ref="totprecip" minOccurs="1" maxOccurs="1" />
+                               <xsd:element ref="grndsnowlastday" minOccurs="1" maxOccurs="1" />
+                               <xsd:element ref="dirmaxgust" minOccurs="1" maxOccurs="1" />
+                               <xsd:element ref="speedmaxgust" minOccurs="1" maxOccurs="1" />
+                       </xsd:sequence>
+                       <xsd:attributeGroup ref="attrgroup-stationdata" />
+               </xsd:complexType>
+       </xsd:element>
+
+       <xsd:element name="meanmaxtemp">
+               <xsd:complexType>
+                       <xsd:simpleContent>
+                               <xsd:extension base="meanmaxtemp-values">
+                                       <xsd:attributeGroup ref="attrgroup-meanmaxtemp" />
+                               </xsd:extension>
+                       </xsd:simpleContent>
+               </xsd:complexType>
+       </xsd:element>
+
+       <xsd:element name="meanmintemp">
+               <xsd:complexType>
+                       <xsd:simpleContent>
+                               <xsd:extension base="meanmintemp-values">
+                                       <xsd:attributeGroup ref="attrgroup-meanmintemp" />
+                               </xsd:extension>
+                       </xsd:simpleContent>
+               </xsd:complexType>
+       </xsd:element>
+
+       <xsd:element name="meanmonthtemp">
+               <xsd:complexType>
+                       <xsd:simpleContent>
+                               <xsd:extension base="meanmonthtemp-values">
+                                       <xsd:attributeGroup ref="attrgroup-meanmonthtemp" />
+                               </xsd:extension>
+                       </xsd:simpleContent>
+               </xsd:complexType>
+       </xsd:element>
+
+       <xsd:element name="extrmaxtemp">
+               <xsd:complexType>
+                       <xsd:simpleContent>
+                               <xsd:extension base="extrmaxtemp-values">
+                                       <xsd:attributeGroup ref="attrgroup-extrmaxtemp" />
+                               </xsd:extension>
+                       </xsd:simpleContent>
+               </xsd:complexType>
+       </xsd:element>
+
+       <xsd:element name="extrmintemp">
+               <xsd:complexType>
+                       <xsd:simpleContent>
+                               <xsd:extension base="extrmintemp-values">
+                                       <xsd:attributeGroup ref="attrgroup-extrmintemp" />
+                               </xsd:extension>
+                       </xsd:simpleContent>
+               </xsd:complexType>
+       </xsd:element>
+
+       <xsd:element name="totrain">
+               <xsd:complexType>
+                       <xsd:simpleContent>
+                               <xsd:extension base="total-rain-values">
+                                       <xsd:attributeGroup ref="attrgroup-totrain" />
+                               </xsd:extension>
+                       </xsd:simpleContent>
+               </xsd:complexType>
+       </xsd:element>
+
+       <xsd:element name="totsnow">
+               <xsd:complexType>
+                       <xsd:simpleContent>
+                               <xsd:extension base="total-snow-values">
+                                       <xsd:attributeGroup ref="attrgroup-totsnow" />
+                               </xsd:extension>
+                       </xsd:simpleContent>
+               </xsd:complexType>
+       </xsd:element>
+
+       <xsd:element name="totprecip">
+               <xsd:complexType>
+                       <xsd:simpleContent>
+                               <xsd:extension base="total-precipitation-values">
+                                       <xsd:attributeGroup ref="attrgroup-totprecipitation" />
+                               </xsd:extension>
+                       </xsd:simpleContent>
+               </xsd:complexType>
+       </xsd:element>
+
+       <xsd:element name="grndsnowlastday">
+               <xsd:complexType>
+                       <xsd:simpleContent>
+                               <xsd:extension base="total-grndsnowlastday">
+                                       <xsd:attributeGroup ref="attrgroup-grndsnowlastday" />
+                               </xsd:extension>
+                       </xsd:simpleContent>
+               </xsd:complexType>
+       </xsd:element>
+
+       <xsd:element name="dirmaxgust">
+               <xsd:complexType>
+                       <xsd:simpleContent>
+                               <xsd:extension base="total-dirmaxgust">
+                                       <xsd:attributeGroup ref="attrgroup-dirmaxgust" />
+                               </xsd:extension>
+                       </xsd:simpleContent>
+               </xsd:complexType>
+       </xsd:element>
+
+       <xsd:element name="speedmaxgust">
+               <xsd:complexType>
+                       <xsd:simpleContent>
+                               <xsd:extension base="total-speedmaxgust">
+                                       <xsd:attributeGroup ref="attrgroup-speedmaxgust" />
+                               </xsd:extension>
+                       </xsd:simpleContent>
+               </xsd:complexType>
+       </xsd:element>
+
+       <!-- Define attributes -->
+       <xsd:attribute name="flag">
+               <xsd:annotation>
+                       <xsd:documentation xml:lang="en">flag attribute has only one value
+                       </xsd:documentation>
+               </xsd:annotation>
+               <xsd:simpleType>
+                       <xsd:restriction base="xsd:string">
+                               <xsd:length value="1" />
+                       </xsd:restriction>
+               </xsd:simpleType>
+       </xsd:attribute>
+
+       <!-- Define groups -->
+
+       <!-- Define attributes groups -->
+       <xsd:attributeGroup name="attrgroup-stationdata">
+               <xsd:attribute name="month" use="required">
+                       <xsd:simpleType>
+                               <xsd:restriction base="xsd:integer">
+                                       <xsd:minInclusive value="1" />
+                                       <xsd:maxInclusive value="12" />
+                               </xsd:restriction>
+                       </xsd:simpleType>
+               </xsd:attribute>
+               <xsd:attribute name="year" use="required">
+                       <xsd:simpleType>
+                               <xsd:restriction base="xsd:integer">
+                                       <xsd:minInclusive value="1840" />
+                                       <xsd:maxInclusive value="2019" />
+                               </xsd:restriction>
+                       </xsd:simpleType>
+               </xsd:attribute>
+       </xsd:attributeGroup>
+
+       <xsd:attributeGroup name="attrgroup-meanmaxtemp">
+               <xsd:attribute name="units" use="required">
+                       <xsd:simpleType>
+                               <xsd:restriction base="xsd:string">
+                                       <xsd:annotation>
+                                               <xsd:documentation xml:lang="en">meanmaxtemp must be provided in Â°C.
+                                               </xsd:documentation>
+                                       </xsd:annotation>
+                                       <xsd:enumeration value="°C" />
+                               </xsd:restriction>
+                       </xsd:simpleType>
+               </xsd:attribute>
+               <xsd:attribute name="description" use="optional" />
+               <xsd:attribute name="flag">
+                       <xsd:simpleType>
+                               <xsd:restriction base="xsd:string">
+                                       <xsd:annotation>
+                                               <xsd:documentation xml:lang="en">meanmaxtemp flag can be E I or M only.
+                                               </xsd:documentation>
+                                       </xsd:annotation>
+                                       <xsd:enumeration value="E" />
+                                       <xsd:enumeration value="I" />
+                                       <xsd:enumeration value="M" />
+                               </xsd:restriction>
+                       </xsd:simpleType>
+               </xsd:attribute>
+       </xsd:attributeGroup>
+
+       <xsd:attributeGroup name="attrgroup-meanmintemp">
+               <xsd:attribute name="units" use="required">
+                       <xsd:simpleType>
+                               <xsd:restriction base="xsd:string">
+                                       <xsd:annotation>
+                                               <xsd:documentation xml:lang="en">meanmintemp must be provided in Â°C.
+                                               </xsd:documentation>
+                                       </xsd:annotation>
+                                       <xsd:enumeration value="°C" />
+                               </xsd:restriction>
+                       </xsd:simpleType>
+               </xsd:attribute>
+               <xsd:attribute name="description" use="optional" />
+               <xsd:attribute name="flag">
+                       <xsd:simpleType>
+                               <xsd:restriction base="xsd:string">
+                                       <xsd:annotation>
+                                               <xsd:documentation xml:lang="en">meanmintemp flag can be E I or M only.
+                                               </xsd:documentation>
+                                       </xsd:annotation>
+                                       <xsd:enumeration value="E" />
+                                       <xsd:enumeration value="I" />
+                                       <xsd:enumeration value="M" />
+                               </xsd:restriction>
+                       </xsd:simpleType>
+               </xsd:attribute>
+       </xsd:attributeGroup>
+
+       <xsd:attributeGroup name="attrgroup-meanmonthtemp">
+               <xsd:attribute name="units" use="required">
+                       <xsd:simpleType>
+                               <xsd:restriction base="xsd:string">
+                                       <xsd:annotation>
+                                               <xsd:documentation xml:lang="en">meanmonthtemp must be provided in Â°C.
+                                               </xsd:documentation>
+                                       </xsd:annotation>
+                                       <xsd:enumeration value="°C" />
+                               </xsd:restriction>
+                       </xsd:simpleType>
+               </xsd:attribute>
+               <xsd:attribute name="description" use="optional" />
+               <xsd:attribute name="flag">
+                       <xsd:simpleType>
+                               <xsd:restriction base="xsd:string">
+                                       <xsd:annotation>
+                                               <xsd:documentation xml:lang="en">meanmonthtemp flag can be E I or M only.
+                                               </xsd:documentation>
+                                       </xsd:annotation>
+                                       <xsd:enumeration value="E" />
+                                       <xsd:enumeration value="I" />
+                                       <xsd:enumeration value="M" />
+                               </xsd:restriction>
+                       </xsd:simpleType>
+               </xsd:attribute>
+       </xsd:attributeGroup>
+
+       <xsd:attributeGroup name="attrgroup-extrmaxtemp">
+               <xsd:attribute name="units" use="required">
+                       <xsd:simpleType>
+                               <xsd:restriction base="xsd:string">
+                                       <xsd:annotation>
+                                               <xsd:documentation xml:lang="en">extrmaxtemp must be provided in Â°C.
+                                               </xsd:documentation>
+                                       </xsd:annotation>
+                                       <xsd:enumeration value="°C" />
+                               </xsd:restriction>
+                       </xsd:simpleType>
+               </xsd:attribute>
+               <xsd:attribute name="description" use="optional" />
+               <xsd:attribute name="flag">
+                       <xsd:simpleType>
+                               <xsd:restriction base="xsd:string">
+                                       <xsd:annotation>
+                                               <xsd:documentation xml:lang="en">extrmaxtemp flag can be B E I M or S only.
+                                               </xsd:documentation>
+                                       </xsd:annotation>
+                                       <xsd:enumeration value="B" />
+                                       <xsd:enumeration value="E" />
+                                       <xsd:enumeration value="I" />
+                                       <xsd:enumeration value="M" />
+                                       <xsd:enumeration value="S" />
+                               </xsd:restriction>
+                       </xsd:simpleType>
+               </xsd:attribute>
+       </xsd:attributeGroup>
+
+       <xsd:attributeGroup name="attrgroup-extrmintemp">
+               <xsd:attribute name="units" use="required">
+                       <xsd:simpleType>
+                               <xsd:restriction base="xsd:string">
+                                       <xsd:annotation>
+                                               <xsd:documentation xml:lang="en">extrmintemp must be provided in Â°C.
+                                               </xsd:documentation>
+                                       </xsd:annotation>
+                                       <xsd:enumeration value="°C" />
+                               </xsd:restriction>
+                       </xsd:simpleType>
+               </xsd:attribute>
+               <xsd:attribute name="description" use="optional" />
+               <xsd:attribute name="flag">
+                       <xsd:simpleType>
+                               <xsd:restriction base="xsd:string">
+                                       <xsd:annotation>
+                                               <xsd:documentation xml:lang="en">extrmintemp flag can be B E I M or S only.
+                                               </xsd:documentation>
+                                       </xsd:annotation>
+                                       <xsd:enumeration value="B" />
+                                       <xsd:enumeration value="E" />
+                                       <xsd:enumeration value="I" />
+                                       <xsd:enumeration value="M" />
+                                       <xsd:enumeration value="S" />
+                               </xsd:restriction>
+                       </xsd:simpleType>
+               </xsd:attribute>
+       </xsd:attributeGroup>
+
+       <xsd:attributeGroup name="attrgroup-totrain">
+               <xsd:attribute name="units" use="required">
+                       <xsd:simpleType>
+                               <xsd:restriction base="xsd:string">
+                                       <xsd:annotation>
+                                               <xsd:documentation xml:lang="en">totrain unit must be provided in mm.
+                                               </xsd:documentation>
+                                       </xsd:annotation>
+                                       <xsd:enumeration value="mm" />
+                               </xsd:restriction>
+                       </xsd:simpleType>
+               </xsd:attribute>
+               <xsd:attribute name="description" use="optional" />
+               <xsd:attribute name="flag">
+                       <xsd:simpleType>
+                               <xsd:restriction base="xsd:string">
+                                       <xsd:annotation>
+                                               <xsd:documentation xml:lang="en">totrain flag can be E I M or T only.
+                                               </xsd:documentation>
+                                       </xsd:annotation>
+                                       <xsd:enumeration value="E" />
+                                       <xsd:enumeration value="I" />
+                                       <xsd:enumeration value="M" />
+                                       <xsd:enumeration value="T" />
+                               </xsd:restriction>
+                       </xsd:simpleType>
+               </xsd:attribute>
+       </xsd:attributeGroup>
+
+       <xsd:attributeGroup name="attrgroup-totsnow">
+               <xsd:attribute name="units" use="required">
+                       <xsd:simpleType>
+                               <xsd:restriction base="xsd:string">
+                                       <xsd:annotation>
+                                               <xsd:documentation xml:lang="en">totsnow unit must be provided in cm.
+                                               </xsd:documentation>
+                                       </xsd:annotation>
+                                       <xsd:enumeration value="cm" />
+                               </xsd:restriction>
+                       </xsd:simpleType>
+               </xsd:attribute>
+               <xsd:attribute name="description" use="optional" />
+               <xsd:attribute name="flag">
+                       <xsd:simpleType>
+                               <xsd:restriction base="xsd:string">
+                                       <xsd:annotation>
+                                               <xsd:documentation xml:lang="en">totrain flag can be E I M or T only.
+                                               </xsd:documentation>
+                                       </xsd:annotation>
+                                       <xsd:enumeration value="E" />
+                                       <xsd:enumeration value="I" />
+                                       <xsd:enumeration value="M" />
+                                       <xsd:enumeration value="T" />
+                               </xsd:restriction>
+                       </xsd:simpleType>
+               </xsd:attribute>
+       </xsd:attributeGroup>
+
+       <xsd:attributeGroup name="attrgroup-totprecipitation">
+               <xsd:attribute name="units" use="required">
+                       <xsd:simpleType>
+                               <xsd:restriction base="xsd:string">
+                                       <xsd:annotation>
+                                               <xsd:documentation xml:lang="en">totprecip unit must be provided in mm.
+                                               </xsd:documentation>
+                                       </xsd:annotation>
+                                       <xsd:enumeration value="mm" />
+                               </xsd:restriction>
+                       </xsd:simpleType>
+               </xsd:attribute>
+               <xsd:attribute name="description" use="optional" />
+               <xsd:attribute name="flag">
+                       <xsd:simpleType>
+                               <xsd:restriction base="xsd:string">
+                                       <xsd:annotation>
+                                               <xsd:documentation xml:lang="en">totprecip flag can be E I M or T only.
+                                               </xsd:documentation>
+                                       </xsd:annotation>
+                                       <xsd:enumeration value="E" />
+                                       <xsd:enumeration value="I" />
+                                       <xsd:enumeration value="M" />
+                                       <xsd:enumeration value="T" />
+                               </xsd:restriction>
+                       </xsd:simpleType>
+               </xsd:attribute>
+       </xsd:attributeGroup>
+
+       <xsd:attributeGroup name="attrgroup-grndsnowlastday">
+               <xsd:attribute name="units" use="required">
+                       <xsd:simpleType>
+                               <xsd:restriction base="xsd:string">
+                                       <xsd:annotation>
+                                               <xsd:documentation xml:lang="en">grndsnowlastday unit must be provided in cm.
+                                               </xsd:documentation>
+                                       </xsd:annotation>
+                                       <xsd:enumeration value="cm" />
+                               </xsd:restriction>
+                       </xsd:simpleType>
+               </xsd:attribute>
+               <xsd:attribute name="description" use="optional" />
+               <xsd:attribute name="flag">
+                       <xsd:simpleType>
+                               <xsd:restriction base="xsd:string">
+                                       <xsd:annotation>
+                                               <xsd:documentation xml:lang="en">grndsnowlastday flag can be E M or T only.
+                                               </xsd:documentation>
+                                       </xsd:annotation>
+                                       <xsd:enumeration value="E" />
+                                       <xsd:enumeration value="M" />
+                                       <xsd:enumeration value="T" />
+                               </xsd:restriction>
+                       </xsd:simpleType>
+               </xsd:attribute>
+       </xsd:attributeGroup>
+
+       <xsd:attributeGroup name="attrgroup-dirmaxgust">
+               <xsd:attribute name="units" use="required">
+                       <xsd:simpleType>
+                               <xsd:restriction base="xsd:string">
+                                       <xsd:annotation>
+                                               <xsd:documentation xml:lang="en">dirmaxgust unit must be provided in 10's Deg.
+                                               </xsd:documentation>
+                                       </xsd:annotation>
+                                       <xsd:enumeration value="10's Deg" />
+                               </xsd:restriction>
+                       </xsd:simpleType>
+               </xsd:attribute>
+               <xsd:attribute name="description" use="optional" />
+               <xsd:attribute name="flag">
+                       <xsd:simpleType>
+                               <xsd:restriction base="xsd:string">
+                                       <xsd:annotation>
+                                               <xsd:documentation xml:lang="en">dirmaxgust flag can be B E I M or S only.
+                                               </xsd:documentation>
+                                       </xsd:annotation>
+                                       <xsd:enumeration value="B" />
+                                       <xsd:enumeration value="E" />
+                                       <xsd:enumeration value="I" />
+                                       <xsd:enumeration value="M" />
+                                       <xsd:enumeration value="S" />
+                               </xsd:restriction>
+                       </xsd:simpleType>
+               </xsd:attribute>
+       </xsd:attributeGroup>
+
+       <xsd:attributeGroup name="attrgroup-speedmaxgust">
+               <xsd:attribute name="units" use="required">
+                       <xsd:simpleType>
+                               <xsd:restriction base="xsd:string">
+                                       <xsd:annotation>
+                                               <xsd:documentation xml:lang="en">speedmaxgust unit must be provided in km/h.
+                                               </xsd:documentation>
+                                       </xsd:annotation>
+                                       <xsd:enumeration value="km/h"/>
+                               </xsd:restriction>
+                       </xsd:simpleType>
+               </xsd:attribute>
+               <xsd:attribute name="description" use="optional" />
+               <xsd:attribute name="flag">
+                       <xsd:simpleType>
+                               <xsd:restriction base="xsd:string">
+                                       <xsd:annotation>
+                                               <xsd:documentation xml:lang="en">speedmaxgust flag can be B E I M or S only.
+                                               </xsd:documentation>
+                                       </xsd:annotation>
+                                       <xsd:enumeration value="B" />
+                                       <xsd:enumeration value="E" />
+                                       <xsd:enumeration value="I" />
+                                       <xsd:enumeration value="M" />
+                                       <xsd:enumeration value="S" />
+                               </xsd:restriction>
+                       </xsd:simpleType>
+               </xsd:attribute>
+       </xsd:attributeGroup>
+
+       <!-- Define types -->
+       <xsd:simpleType name="meanmaxtemp-values">
+               <xsd:union memberTypes="empty">
+                       <xsd:simpleType>
+                               <xsd:restriction base="xsd:float">
+                                       <xsd:minInclusive value="-45.6" />
+                                       <xsd:maxInclusive value="35.8">
+                                               <xsd:annotation>
+                                                       <xsd:documentation xml:lang="en">Max value is currently 19.3.
+                                                       </xsd:documentation>
+                                               </xsd:annotation>
+                                       </xsd:maxInclusive>
+                               </xsd:restriction>
+                       </xsd:simpleType>
+               </xsd:union>
+       </xsd:simpleType>
+
+       <xsd:simpleType name="meanmintemp-values">
+               <xsd:union memberTypes="empty">
+                       <xsd:simpleType>
+                               <xsd:restriction base="xsd:float">
+                                       <xsd:minInclusive value="-50.1" />
+                                       <xsd:maxInclusive value="22.3">
+                                               <xsd:annotation>
+                                                       <xsd:documentation xml:lang="en">Max value is currently 22.3.
+                                                       </xsd:documentation>
+                                               </xsd:annotation>
+                                       </xsd:maxInclusive>
+                               </xsd:restriction>
+                       </xsd:simpleType>
+               </xsd:union>
+       </xsd:simpleType>
+
+       <xsd:simpleType name="meanmonthtemp-values">
+               <xsd:union memberTypes="empty">
+                       <xsd:simpleType>
+                               <xsd:restriction base="xsd:float">
+                                       <xsd:minInclusive value="-47.9" />
+                                       <xsd:maxInclusive value="27.2">
+                                               <xsd:annotation>
+                                                       <xsd:documentation xml:lang="en">Max value is currently 27.2.
+                                                       </xsd:documentation>
+                                               </xsd:annotation>
+                                       </xsd:maxInclusive>
+                               </xsd:restriction>
+                       </xsd:simpleType>
+               </xsd:union>
+       </xsd:simpleType>
+
+       <xsd:simpleType name="extrmaxtemp-values">
+               <xsd:union memberTypes="empty">
+                       <xsd:simpleType>
+                               <xsd:restriction base="xsd:float">
+                                       <xsd:minInclusive value="-40.0" />
+                                       <xsd:maxInclusive value="45.0">
+                                               <xsd:annotation>
+                                                       <xsd:documentation xml:lang="en">Max value is currently 45.0.
+                                                       </xsd:documentation>
+                                               </xsd:annotation>
+                                       </xsd:maxInclusive>
+                               </xsd:restriction>
+                       </xsd:simpleType>
+               </xsd:union>
+       </xsd:simpleType>
+
+       <xsd:simpleType name="extrmintemp-values">
+               <xsd:union memberTypes="empty">
+                       <xsd:simpleType>
+                               <xsd:restriction base="xsd:float">
+                                       <xsd:minInclusive value="-63" />
+                                       <xsd:maxInclusive value="37.3">
+                                               <xsd:annotation>
+                                                       <xsd:documentation xml:lang="en">Max value is currently 37.3.
+                                                       </xsd:documentation>
+                                               </xsd:annotation>
+                                       </xsd:maxInclusive>
+                               </xsd:restriction>
+                       </xsd:simpleType>
+               </xsd:union>
+       </xsd:simpleType>
+
+       <xsd:simpleType name="total-rain-values">
+               <xsd:union memberTypes="sharps empty">
+                       <xsd:annotation>
+                               <xsd:documentation xml:lang="en">WARNING:
+                                       17/monthly/en_climate_monthly_BC_1010720_1910-1971_P1M.xml:32:616122
+                                       Contains only sharps instead of a float or empty content
+                               </xsd:documentation>
+                       </xsd:annotation>
+                       <xsd:simpleType>
+                               <xsd:restriction base="xsd:float">
+                                       <xsd:minInclusive value="0" />
+                                       <xsd:maxInclusive value="999.5">
+                                               <xsd:annotation>
+                                                       <xsd:documentation xml:lang="en">TBD: Max value is currently 999.2.
+                                                               Is it expected? Looks high and arbitrary cut at 1000.
+                                                       </xsd:documentation>
+                                               </xsd:annotation>
+                                       </xsd:maxInclusive>
+                               </xsd:restriction>
+                       </xsd:simpleType>
+               </xsd:union>
+       </xsd:simpleType>
+
+       <xsd:simpleType name="total-snow-values">
+               <xsd:union memberTypes="empty">
+                       <xsd:annotation>
+                               <xsd:documentation xml:lang="en">No value is allowed
+                               </xsd:documentation>
+                       </xsd:annotation>
+                       <xsd:simpleType>
+                               <xsd:restriction base="xsd:float">
+                                       <xsd:minInclusive value="-15.1">
+                                               <xsd:annotation>
+                                                       <xsd:documentation xml:lang="en">WARNING:
+                                                               monthly/3953/en_climate_monthly_ON_6032119_1970-2004_P1M.xml:32:261659
+                                                               Has negative totsnow value (-15.1)
+                                                       </xsd:documentation>
+                                               </xsd:annotation>
+                                       </xsd:minInclusive>
+                                       <xsd:maxInclusive value="726">
+                                               <xsd:annotation>
+                                                       <xsd:documentation xml:lang="en">Max value is currently 725.9.
+                                                       </xsd:documentation>
+                                               </xsd:annotation>
+                                       </xsd:maxInclusive>
+                               </xsd:restriction>
+                       </xsd:simpleType>
+               </xsd:union>
+       </xsd:simpleType>
+
+       <xsd:simpleType name="total-precipitation-values">
+               <xsd:union memberTypes="sharps empty">
+                       <xsd:annotation>
+                               <xsd:documentation xml:lang="en">WARNING:
+                                       17/monthly/en_climate_monthly_BC_1010720_1910-1971_P1M.xml:32:73731
+                                       Contains only sharps instead of a float or empty content
+                               </xsd:documentation>
+                       </xsd:annotation>
+                       <xsd:simpleType>
+                               <xsd:restriction base="xsd:float">
+                                       <xsd:minInclusive value="0">
+                                               <xsd:annotation>
+                                                       <xsd:documentation xml:lang="en">No negative precipitation value allowed.
+                                                       </xsd:documentation>
+                                               </xsd:annotation>
+                                       </xsd:minInclusive>
+                                       <xsd:maxInclusive value="999.5">
+                                               <xsd:annotation>
+                                                       <xsd:documentation xml:lang="en">Max value is currently 999.2.
+                                                               Is it expected? Looks high and arbitrary cut at 1000.
+                                                       </xsd:documentation>
+                                               </xsd:annotation>
+                                       </xsd:maxInclusive>
+                               </xsd:restriction>
+                       </xsd:simpleType>
+               </xsd:union>
+       </xsd:simpleType>
+
+       <xsd:simpleType name="total-grndsnowlastday">
+               <xsd:union memberTypes="empty">
+                       <xsd:annotation>
+                               <xsd:documentation xml:lang="en">No value is allowed
+                               </xsd:documentation>
+                       </xsd:annotation>
+                       <xsd:simpleType>
+                               <xsd:restriction base="xsd:integer">
+                                       <xsd:minInclusive value="0">
+                                               <xsd:annotation>
+                                                       <xsd:documentation xml:lang="en">No negative precipitation value allowed.
+                                                       </xsd:documentation>
+                                               </xsd:annotation>
+                                       </xsd:minInclusive>
+                                       <xsd:maxInclusive value="955">
+                                               <xsd:annotation>
+                                                       <xsd:documentation xml:lang="en">Max value is currently 955.
+                                                               Is it expected? Looks high and arbitrary cut at 1000.
+                                                       </xsd:documentation>
+                                               </xsd:annotation>
+                                       </xsd:maxInclusive>
+                               </xsd:restriction>
+                       </xsd:simpleType>
+               </xsd:union>
+       </xsd:simpleType>
+
+       <xsd:simpleType name="total-dirmaxgust">
+               <xsd:union memberTypes="empty">
+                       <xsd:annotation>
+                               <xsd:documentation xml:lang="en">No value is allowed
+                               </xsd:documentation>
+                       </xsd:annotation>
+                       <xsd:simpleType>
+                               <xsd:restriction base="xsd:integer">
+                                       <xsd:minInclusive value="0">
+                                               <xsd:annotation>
+                                                       <xsd:documentation xml:lang="en">No negative orientation value allowed. Value of 0 is allowed
+                                                       </xsd:documentation>
+                                               </xsd:annotation>
+                                       </xsd:minInclusive>
+                                       <xsd:maxInclusive value="36">
+                                               <xsd:annotation>
+                                                       <xsd:documentation xml:lang="en">WARNING: Value of 36 is allowed.
+                                                       </xsd:documentation>
+                                               </xsd:annotation>
+                                       </xsd:maxInclusive>
+                               </xsd:restriction>
+                       </xsd:simpleType>
+               </xsd:union>
+       </xsd:simpleType>
+
+       <xsd:simpleType name="total-speedmaxgust">
+               <xsd:union memberTypes="lt31 empty">
+                       <xsd:annotation>
+                               <xsd:documentation xml:lang="en">No value is allowed
+                               </xsd:documentation>
+                       </xsd:annotation>
+                       <xsd:simpleType>
+                               <xsd:restriction base="xsd:integer">
+                                       <xsd:minInclusive value="0">
+                                               <xsd:annotation>
+                                                       <xsd:documentation xml:lang="en">No negative speed allowed.
+                                                       </xsd:documentation>
+                                               </xsd:annotation>
+                                       </xsd:minInclusive>
+                                       <xsd:maxInclusive value="467">
+                                               <xsd:annotation>
+                                                       <xsd:documentation xml:lang="en">WARNING: Max value is currently 467.
+                                                               Probably an error
+                                                       </xsd:documentation>
+                                               </xsd:annotation>
+                                       </xsd:maxInclusive>
+                               </xsd:restriction>
+                       </xsd:simpleType>
+               </xsd:union>
+       </xsd:simpleType>
+
+       <xsd:simpleType name="empty">
+               <xsd:restriction base="xsd:string">
+                       <xsd:length value="0" />
+               </xsd:restriction>
+       </xsd:simpleType>
+
+       <xsd:simpleType name="zero">
+               <xsd:restriction base="xsd:float">
+                       <xsd:enumeration value="0.0" />
+               </xsd:restriction>
+       </xsd:simpleType>
+
+       <xsd:simpleType name="sharps">
+               <xsd:restriction base="xsd:string">
+                       <xsd:pattern value="#+" />
+               </xsd:restriction>
+       </xsd:simpleType>
+
+       <xsd:simpleType name="lt31">
+               <xsd:restriction base="xsd:string">
+                       <xsd:pattern value="&lt;31" />
+               </xsd:restriction>
+       </xsd:simpleType>
+</xsd:schema>
diff --git a/eccc_fixer.xslt b/eccc_fixer.xslt
new file mode 100644 (file)
index 0000000..b62098a
--- /dev/null
@@ -0,0 +1,19 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+                xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+       <xsl:output method="xml" encoding="utf-8" />
+
+       <!-- Idempotence -->
+       <xsl:template match="node()|@*">
+               <xsl:copy>
+                       <xsl:apply-templates select="node()|@*" />
+               </xsl:copy>
+       </xsl:template>
+
+       <xsl:template match="/climatedata">
+               <climatedata>
+                       <xsl:attribute name="xsi:schemaLocation">http://climate.weather.gc.ca/climate_data/bulkxml/bulkschema.xsd</xsl:attribute>
+                       <xsl:apply-templates />
+               </climatedata>
+       </xsl:template>
+</xsl:stylesheet>