Skip to content

Instantly share code, notes, and snippets.

@djbpitt
Created November 14, 2024 00:20
Show Gist options
  • Save djbpitt/3e3768364fb9287c6d50241d5b48e6f5 to your computer and use it in GitHub Desktop.
Save djbpitt/3e3768364fb9287c6d50241d5b48e6f5 to your computer and use it in GitHub Desktop.
Mitford geo info as json
<?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" xpath-default-namespace="http://www.tei-c.org/ns/1.0"
xmlns:fn="http://www.w3.org/2005/xpath-functions"
xmlns:math="http://www.w3.org/2005/xpath-functions/math" exclude-result-prefixes="#all"
version="3.0">
<xsl:output method="text" indent="yes"/>
<!-- ================================================================= -->
<!-- Stylesheet variables -->
<!-- ================================================================= -->
<xsl:variable name="corpus" as="document-node()+" select="collection('data?select=*.xml')"/>
<xsl:variable name="gazetteer" as="document-node()"
select="document('http://raw.githubusercontent.com/DigitalMitford/DM_SiteIndex/refs/heads/master/si_Full_Staged/si.xml')"/>
<xsl:variable name="json-options" as="map(*)">
<xsl:map>
<xsl:map-entry key="'indent'" select="true()"/>
</xsl:map>
</xsl:variable>
<!-- ================================================================= -->
<!-- Templates -->
<!-- ================================================================= -->
<xsl:template name="xsl:initial-template">
<xsl:variable name="result">
<fn:array>
<xsl:apply-templates select="$corpus"/>
</fn:array>
</xsl:variable>
<xsl:sequence select="xml-to-json($result, $json-options)"/>
</xsl:template>
<xsl:template match="/">
<fn:map>
<xsl:for-each select="distinct-values(descendant::placeName/@ref) ! substring(., 2)">
<fn:string key="{translate(., '_', ' ')}">
<xsl:value-of select="id(., $gazetteer)/descendant::geo"/>
</fn:string>
</xsl:for-each>
</fn:map>
</xsl:template>
</xsl:stylesheet>
@djbpitt
Copy link
Author

djbpitt commented Nov 14, 2024

Output:

 [ 
  { "Bertram house" : "",
   "Hampshire county" : "51.05769480000001 -1.3080628999999817",
   "London city" : "51.5073509 -0.12775829999998223",
   "Stratford upon Avon city" : "52.19173 -1.7082980000000134" },
  
  { "Coley Berks" : "51.4432268 -0.9902848000000404",
   "Devonshire" : "50.7155591 -3.5308750000000373",
   "Devonshire county" : "50.716667 -3.716667",
   "Europe" : "54.883056 15.430833",
   "France" : "46.227638 2.213749000000007",
   "Germany" : "51.165691 10.451526000000058",
   "India" : "20.593684 78.96288000000004",
   "Italy" : "41.87194 12.567379999999957",
   "Mortimer Comm" : "51.3770005 -1.0629936999999927",
   "Plymouth city" : "50.3754565 -4.14265649999993",
   "Reading city" : "51.4542645 -0.9781302999999753",
   "Rome" : "41.9027835 12.496365500000024",
   "Savona" : "44.3425496 8.42938909999998",
   "Styx" : "",
   "Switzerland" : "46.95, 7.45" },
  
  { "Bertram house" : "",
   "Hampshire county" : "51.05769480000001 -1.3080628999999817",
   "London city" : "51.5073509 -0.12775829999998223",
   "Stratford upon Avon city" : "52.19173 -1.7082980000000134" } ]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment