Created
November 14, 2024 00:20
-
-
Save djbpitt/3e3768364fb9287c6d50241d5b48e6f5 to your computer and use it in GitHub Desktop.
Mitford geo info as json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Output: