Skip to content

Instantly share code, notes, and snippets.

@fidothe
Created May 12, 2023 08:16
Show Gist options
  • Save fidothe/5442c1e8770e8275334bebedbdafce28 to your computer and use it in GitHub Desktop.
Save fidothe/5442c1e8770e8275334bebedbdafce28 to your computer and use it in GitHub Desktop.

Some redacted/anonymised/simplified example CSVs from real-world projects I've worked on, along with as-trivial-as-possible example usage via XSLT.

This initial version is incomplete and very hurried, I'll finish and polish to whatever degree is useful later

000100 000099 1100 Service Ticket In Progress Telephone call Telephone call 1 1 1 N 1
000101 R 1200 Service Related Service Ticket In Progress Allocated to Service Area Specialist Web Channel Website 1 Street Trees 10 2 Website N 1
000102 R 1300 Your Views 'Your Views' In Progress Investigating Telephone call Call Centre 1 Call Centre 1 1 Call Centre N 1
000103 R 1600 Service Related Service Ticket In Progress Assigned - To Service Area Telephone call Call Centre 1 Call Centre 1 1 Call Centre Ladywood Constituency Ladywood N 1
000104 R 1500 Service Related Service Ticket In Progress Ready for Submission Telephone call Call Centre 1 Landlords 1 1 Call Centre Erdington Constituency Kingstanding N 1
000105 R 1700 Service Related Service Ticket In Progress Completed - Service Delivered Web Channel Website 3 Missed Collection 100 3 Website N 1
000106 R 1600 Service Related Service Ticket In Progress Assigned - To Service Area Telephone call Call Centre 1 Call Centre 1 1 Call Centre Ladywood Constituency Ladywood N 1
000107 R 1500 Service Related Service Ticket Re-Opened Requested by the Council Telephone call Call Centre 3 First Response 100 1 Call Centre Hall Green Constituency Springfield Y N 1
000108 000080 1100 Service Ticket In Progress Telephone call Telephone call 1 1 1 Y N 1
000109 1300 Service Related Service Ticket Closed Telephone call Election Enquiries 3 Election Enquiries 100 3 Election Enquiries N 1
000110 R 900 Book Service Ticket Pending Web Channel Website 1 1 1 Website N 1
000111 75 G 1600 Book Booking Closed Telephone call Appointment Tenants 1 Area 1 NO 10 2 Tenants N 1
000112 G 1000 Service Related Service Ticket Closed Telephone call Election Enquiries 3 Election Enquiries 100 3 Election Enquiries N 1
000113 R 1400 Service Related Service Ticket In Progress Completed - Service Delivered Web Channel Website 3 Missed Collection 100 3 Website Erdington Constituency Stockland Green N 1
000114 R 1700 Your Views 'Your Views' In Progress Investigating Web Channel Website 1 1 1 Website N 1
000115 R 1600 Service Related Service Ticket In Progress Assigned - To Service Area Telephone call Call Centre 1 Call Centre 1 1 Call Centre Ladywood Constituency Ladywood N 1
000116 000102 R 1700 Your Views 'Your Views' In Progress Investigating Telephone call Web Channel Website 1 Neighbourhood Offices 1 2 Website N 1
000117 76 G 1400 Book Booking Cancelled Cancelled by system Telephone call Appointment Tenants 1 Area 1 NO 10 2 Tenants N 1
000118 1100 Provide Information Service Ticket In Progress Scheduled Web Channel Website 1 1 1 Website N 1
000119 1600 Service Related Service Ticket In Progress Telephone call Call Centre 1 Call Centre 1 1 Call Centre Ladywood Constituency Ladywood N 1
000120 R 1600 Service Related Service Ticket In Progress Assigned - To Service Area Telephone call Call Centre 1 Call Centre 1 1 Call Centre Ladywood Constituency Ladywood N 1
000121 G 1600 Service Related Service Ticket Closed Telephone call Tenants 1 Tenants 1 1 Tenants N 1
000122 R 1000 Service Related Service Ticket In Progress Telephone call Election Enquiries 3 Election Enquiries 100 3 Election Enquiries N 1
000123 1800 Provide Information Service Ticket Closed Telephone call Social Care 1 Social Care 1 1 Social Care N 1
000124 R 1100 Service Related Service Ticket In Progress Completed - Service Delivered Web Channel Website 3 Missed Collection 100 3 Website N 1
000125 000060 1100 Service Ticket In Progress Telephone call Telephone call 1 1 1 Y N 1
000126 1100 Service Related Service Ticket Closed Telephone call Call Centre 1 Call Centre 1 1 Call Centre N 1
000127 1100 Service Related Service Ticket Closed Telephone call Call Centre 1 Call Centre 1 1 Call Centre Ladywood Constituency Ladywood N 1
000128 R 1600 Service Related Service Ticket In Progress Assigned - To Service Area Telephone call Call Centre 1 Call Centre 1 1 Call Centre Ladywood Constituency Ladywood N 1
000131 1600 Service Related Service Ticket In Progress Telephone call Call Centre 1 Call Centre 1 1 Call Centre Ladywood Constituency Ladywood N 1
000132 R 1600 Service Related Service Ticket In Progress Assigned - To Service Area Telephone call Call Centre 1 Call Centre 1 1 Call Centre Ladywood Constituency Ladywood N 1
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
exclude-result-prefixes="xs"
version="4.0">
<xsl:variable name="stt" select="doc('stt.xml')"/> <!-- generated by stt-example.xsl -->
<xsl:variable name="headers" select="map { 'id': 1, 'status': 7, 'department': 13 }"/>
<xsl:template name="xsl:initial-template">
<contacts>
<xsl:for-each select="fn:parse-csv(fn:unparsed-text('dashboard-example.csv'), map { 'headers': false() })">
<contact id=".($headers?id)">
<department ref="$stt//level[name = .($headers?department)]/@id"/>
<status><xsl:value-of select=".($headers?status)"/></status>
</contact>
</xsl:for-each>
</contacts>
</xsl:template>
</xsl:stylesheet>
Level 1 Level 2 Level 3 Level 4
Constituencies
Constituencies Constituencies
Constituencies Constituencies Neighbourhood Offices
Constituencies Constituencies Neighbourhood Offices Area 1 NO
Constituencies Constituencies Neighbourhood Offices Area 2 NO
Social Services
Social Services Healthcare
Social Services Healthcare OthHealthcare
Social Services Healthcare OthHealthcare Social Care
Chief Exec's
Chief Exec's Local Govt Elections
Chief Exec's Local Govt Elections Local Govt Elections
Chief Exec's Local Govt Elections Local Govt Elections Election Enquiries
Transport
Transport Car Parking
Transport Car Parking Enforcement
Transport Car Parking Enforcement First Response
Services
Services Waste Mgt
Services Waste Mgt Refuse and Recycling
Services Waste Mgt Refuse and Recycling Missed Collection
Housing
Housing Housing Needs
Housing Housing Needs Supporting People Landlords
Housing Housing Needs Supporting People Tenants
Culture
Culture Parks & Green space
Culture Parks & Green space Trees Street Trees
Culture Parks & Green space Trees Park Trees
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:f="http://example.org/f"
exclude-result-prefixes="xs"
version="4.0">
<xsl:template name="xsl:initial-template">
<stt>
<xsl:call-template name="level">
<xsl:with-param name="rows" select="fn:parse-csv(fn:unparsed-text('stt-example.csv'), map { headers: true() })?body"/>
<xsl:with-param name="level" select="1"/>
</xsl:call-template>
</stt>
</xsl:template>
<xsl:template name="level">
<xsl:param name="rows" as="array(*)*"/>
<xsl:param name="level" as="xs:integer"/>
<xsl:variable name="next-level" select="$level + 1"/>
<xsl:variable name="selector" select="f:selector($level)"/>
<xsl:for-each-group select="$rows" group-by="$selector(.)">
<xsl:for-each select="current-group()">
<level id="generate-id()" name="current-group()[1]($level)">
<xsl:if test="$next-level < 5">
<xsl:call-template name="level">
<xsl:with-param name="rows" select="tail(current-group())"/>
<xsl:with-param name="level" select="$next-level"/>
</xsl:call-template>
</xsl:if>
</level>
</xsl:for-each>
</xsl:for-each-group>
</xsl:template>
<xsl:function name="f:selector" as="function(array(xs:string*)) as xs:string">
<xsl:param name="column" as="xs:integer"/>
<xsl:sequence select="function(row as array(xs:string*)) { return $row($column) }"/>
</xsl:function>
</xsl:stylesheet>
We can make this file beautiful and searchable if this error is corrected: Any value after quoted field isn't allowed in line 1.
"Umsatz get�tigt von";"Belegdatum";"Buchungsdatum";"Originalbetrag";"Originalw�hrung";"Umrechnungskurs";"Buchungsbetrag";"Buchungsw�hrung";"Transaktionsbeschreibung";"Transaktionsbeschreibung Zusatz";"Buchungsreferenz";"Geb�hrenschl�ssel";"L�nderkennzeichen";"BAR-Entgelt+Buchungsreferenz";"AEE+Buchungsreferenz";"Abrechnungskennzeichen"
"1234 **** **** 1234";"25.12.22";"27.12.22";"-8,70";"EUR";"1,00";"-8,70";"EUR";"Ashop";"Amsterdam";"0";"";"";"";"";""
"1234 **** **** 1234";"16.12.22";"19.12.22";"-0,47";"EUR";"1,00";"-0,47";"EUR";"2,5% f�r W�hrungsumrechnu";"Bshop";"2";"";"";"";"";""
"1234 **** **** 1234";"16.12.22";"19.12.22";"-20,00";"USD";"1,06";"-18,88";"EUR";"Bshop";"San Francisco";"1";"";"";"";"";""
"1234 **** **** 1234";"14.12.22";"14.12.22";"-31,95";"EUR";"1,00";"-31,95";"EUR";"Cshop";"12345678";"3";"";"";"";"";""
"1234 **** **** 1234";"13.12.22";"13.12.22";"-8,00";"USD";"1,05";"-7,61";"EUR";"Dshop";"San Francisco";"4";"";"";"";"";""
"1234 **** **** 1234";"13.12.22";"13.12.22";"-0,19";"EUR";"1,00";"-0,19";"EUR";"2,5% f�r W�hrungsumrechnu";"Dshop";"5";"";"";"";"";""
"1234 **** **** 1234";"09.12.22";"12.12.22";"-319,00";"EUR";"1,00";"-319,00";"EUR";"Eshop";"Luxembourg";"7";"";"";"";"";""
"1234 **** **** 1234";"11.12.22";"12.12.22";"-173,00";"EUR";"1,00";"-173,00";"EUR";"Fshop";"Prague";"6";"";"";"";"";""
"1234 **** **** 1234";"02.12.22";"05.12.22";"-2,81";"EUR";"1,00";"-2,81";"EUR";"Gshop";"internet";"8";"";"";"";"";""
"1234 **** **** 1234";"01.12.22";"01.12.22";"55,60";"EUR";"1,00";"550,60";"EUR";"Abrechnung";"";"10";"";"";"";"";""
MS 1 MS 2 MS 3 MS 4
Stanza Listing Located in previous version at: lines per stanza Ending line number Stanza Listing Located in previous version at: lines per stanza Ending line number Stanza Listing Located in previous version at: lines per stanza Ending line number Stanza Listing Located in previous version at: lines per stanza Ending line number
Book Book Part One Book One
MS1-1 10 10 MS2-1 10 10 MS3-1-1 MS2-1 10 10 MS4-1-1 10 10
MS1-2 10 20 MS2-2 10 20 MS3-1-2 MS2-3 10 20 MS4-1-2 10 20
MS1-3 10 30 MS2-3 10 30 MS3-1-3 MS2-2 10 30 MS4-1-3 MS3-1-1 10 30
MS1-4 10 40 MS2-4 MS1-1 10 40 MS3-1-4 10 40 MS4-1-4 MS3-1-2 10 40
MS1-5 10 50 MS2-5 MS1-8 10 50 MS3-1-5 MS2-5 10 50 MS4-1-5 MS3-1-3 10 50
MS1-6 10 60 MS2-6 10 60 MS3-1-6 10 60 MS4-1-6 56-60:MS3-1-4:31-35 10 60
MS1-7 10 70 MS2-7 10 70 MS3-1-7 MS1-5 10 70 MS4-1-7 61-65:MS3-1-4:36-40 10 70
MS1-8 10 80 MS2-8 MS1-2 10 80 MS3-1-8 MS1-6 10 80 MS4-1-8 10 80
MS2-9 10 90 MS3-1-9 10 90 MS4-1-9 10 90
MS2-10 10 100 MS3-1-10 10 100 MS4-1-10 10 100
MS3-1-11 10 110
Part Two Book Two
MS3-2-1 10 10 MS4-2-1 10 10
MS3-2-2 10 20 MS4-2-2 MS3-1-8 10 20
MS3-2-3 10 30 MS4-2-3 MS3-1-9 10 30
MS3-2-4 10 40 MS4-2-4 MS3-1-10 10 40
MS3-2-5 10 50 MS4-2-5 MS3-1-11 10 50
MS3-2-6 10 60 MS4-2-6 10 60
MS3-2-7 MS2-9:85-90 10 70 MS4-2-7 10 70
MS3-2-8 MS2-10:91-95 10 80 MS4-2-8 10 80
MS3-2-9 10 90 MS4-2-9 10 90
MS3-2-10 10 100 MS4-2-10 10 100
Book Three
MS4-3-1 MS3-2-1 10 10
MS4-3-2 MS3-2-2 10 20
MS4-3-3 MS3-2-3 10 30
MS4-3-4 MS3-2-4 10 40
MS4-3-5 MS3-2-5 10 50
MS4-3-6 MS3-2-6 10 60
MS4-3-7 MS3-2-7 10 70
MS4-3-8 MS3-2-8 10 80
MS4-3-9 MS3-2-9 10 90
MS4-3-10 MS3-2-10 10 100
Book Four
MS4-4-1 10 10
MS4-4-2 10 20
MS4-4-3 10 30
MS4-4-4 10 40
MS4-4-5 10 50
MS4-4-6 10 60
MS4-4-7 10 70
MS4-4-8 10 80
MS4-4-9 10 90
MS4-4-10 10 100
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment