Flatten Tool for IATI¶
Currently flatten-tool only supports Spreadsheet->XML for IATI (unflatten), not conversion in the other direction, or automated template creation.
Convert a spreadsheet to XML¶
For an XLSX file called filename.xlsx
:
flatten-tool unflatten --xml --id-name iati-identifier --root-list-path iati-activity -o iati.xml -f xlsx filename.xlsx
For a directory of CSV files called csv_directory
:
flatten-tool unflatten --xml --id-name iati-identifier --root-list-path iati-activity -o iati.xml -f csv csv_directory
(Outputs a file called iati.xml
).
Example¶
Given these two sheets:
iati-identifier | reporting-org/@ref | reporting-org/@type | reporting-org/narrative | participating-org/@role | participating-org/@ref | activity-status/@code | activity-date/@type | activity-date/@iso-date | recipient-country/0/@code | recipient-country/0/@percentage | recipient-country/1/@code | recipient-country/1/@percentage | title/narrative | description/narrative | @last-updated-datetime |
AA-AAA-123456789-ABC123 | AA-AAA-123456789 | 40 | Organisation name | 1 | AA-AAA-123456789 | 2 | 1 | 2011-10-01 | AF | 40 | XK | 60 | A title | A description | 2011-10-01T00:00:00+00:00 |
AA-AAA-123456789-ABC124 | AA-AAA-123456789 | 40 | Organisation name | 1 | AA-AAA-123456789 | 3 | 2 | 2016-01-01 | AG | 30 | XK | 70 | Another title | Another description | 2016-01-01T00:00:00+00:00 |
iati-identifier | transaction/0/transaction-type/@code | transaction/0/transaction-date/@iso-date | transaction/0/value/@value-date | transaction/0/value |
AA-AAA-123456789-ABC123 | 2 | 2012-01-01 | 2012-01-01 | 10 |
AA-AAA-123456789-ABC123 | 3 | 2012-03-03 | 2012-03-03 | 20 |
AA-AAA-123456789-ABC124 | 2 | 2013-04-04 | 2013-04-04 | 30 |
AA-AAA-123456789-ABC124 | 3 | 2013-05-05 | 2013-05-05 | 40 |
Running this command:
$ flatten-tool unflatten --xml --id-name iati-identifier --root-list-path iati-activity --xml-schema examples/iati/iati-activities-schema.xsd examples/iati/iati-common.xsd -f csv examples/iati
Produces this XML:
<?xml version='1.0' encoding='utf-8'?>
<iati-activities>
<!--XML generated by flatten-tool-->
<iati-activity last-updated-datetime="2011-10-01T00:00:00+00:00">
<iati-identifier>AA-AAA-123456789-ABC123</iati-identifier>
<reporting-org ref="AA-AAA-123456789" type="40">
<narrative>Organisation name</narrative>
</reporting-org>
<title>
<narrative>A title</narrative>
</title>
<description>
<narrative>A description</narrative>
</description>
<participating-org ref="AA-AAA-123456789" role="1"/>
<activity-status code="2"/>
<activity-date iso-date="2011-10-01" type="1"/>
<recipient-country code="AF" percentage="40"/>
<recipient-country code="XK" percentage="60"/>
<transaction>
<transaction-type code="2"/>
<transaction-date iso-date="2012-01-01"/>
<value value-date="2012-01-01">10</value>
</transaction>
<transaction>
<transaction-type code="3"/>
<transaction-date iso-date="2012-03-03"/>
<value value-date="2012-03-03">20</value>
</transaction>
</iati-activity>
<iati-activity last-updated-datetime="2016-01-01T00:00:00+00:00">
<iati-identifier>AA-AAA-123456789-ABC124</iati-identifier>
<reporting-org ref="AA-AAA-123456789" type="40">
<narrative>Organisation name</narrative>
</reporting-org>
<title>
<narrative>Another title</narrative>
</title>
<description>
<narrative>Another description</narrative>
</description>
<participating-org ref="AA-AAA-123456789" role="1"/>
<activity-status code="3"/>
<activity-date iso-date="2016-01-01" type="2"/>
<recipient-country code="AG" percentage="30"/>
<recipient-country code="XK" percentage="70"/>
<transaction>
<transaction-type code="2"/>
<transaction-date iso-date="2013-04-04"/>
<value value-date="2013-04-04">30</value>
</transaction>
<transaction>
<transaction-type code="3"/>
<transaction-date iso-date="2013-05-05"/>
<value value-date="2013-05-05">40</value>
</transaction>
</iati-activity>
</iati-activities>