Skip to content

Instantly share code, notes, and snippets.

@jaw111
Last active September 2, 2019 15:48
Show Gist options
  • Save jaw111/0683c25c2b1f346de9668653e867c23f to your computer and use it in GitHub Desktop.
Save jaw111/0683c25c2b1f346de9668653e867c23f to your computer and use it in GitHub Desktop.
json2rdf
{
"content": [
{
"type": "BUYER",
"status": "RELEASED",
"duns": 214567885,
"vatno": "EU826010123",
"name": "ACME",
"name2": "Acme Corporation",
"website": "http://www.acme.com/",
"street": "Garfield Road",
"streetNr": "498",
"postCode": "61611",
"country": "UNITED STATES",
"code": "AAA000",
"remoteCode": "0001-123456789---ACME_1_1",
"dateEntryKey": 9790294,
"serviceContractor": false,
"companyType": null
},
{
"type": "BUYER",
"status": "RELEASED",
"duns": 231634267,
"vatno": "EU826009061",
"name": "GLOBEX",
"name2": "Globex Corporation",
"website": "https://globex.com/",
"street": "Creekside Lane",
"streetNr": "1a",
"postCode": "93101",
"country": "UNITED STATES",
"code": "AAA001",
"remoteCode": "0001-123456789---SPC_1_1",
"dateEntryKey": 606688,
"serviceContractor": false,
"companyType": null
}
],
"pageable": {
"offset": 0,
"sort": {
"sorted": true,
"unsorted": false,
"empty": false
},
"pageSize": 2,
"pageNumber": 0,
"paged": true,
"unpaged": false
},
"last": false,
"totalPages": 10,
"totalElements": 20,
"sort": {
"sorted": true,
"unsorted": false,
"empty": false
},
"first": true,
"numberOfElements": 2,
"size": 2,
"number": 0,
"empty": false
}
{ "@graph" :
[
{ "@id" : "http:\/\/example.com\/graph\/0001-123456789---ACME_1_1",
"@graph" :
{ "@type" : "http:\/\/example.com\/def\/BUYER",
"type" : "BUYER",
"status" : "RELEASED",
"duns" : "214567885",
"vatno" : "EU826010123",
"name" : "ACME",
"name2" : "Acme Corporation",
"website" : "http:\/\/www.acme.com\/",
"street" : "Garfield Road",
"streetNr" : "498",
"postCode" : "61611",
"country" : "UNITED STATES",
"code" : "AAA000",
"@id" : "http:\/\/example.com\/id\/0001-123456789---ACME_1_1",
"remoteCode" : "0001-123456789---ACME_1_1",
"dateEntryKey" : "9790294",
"serviceContractor" : false } },
{ "@id" : "http:\/\/example.com\/graph\/0001-123456789---SPC_1_1",
"@graph" :
{ "@type" : "http:\/\/example.com\/def\/BUYER",
"type" : "BUYER",
"status" : "RELEASED",
"duns" : "231634267",
"vatno" : "EU826009061",
"name" : "GLOBEX",
"name2" : "Globex Corporation",
"website" : "https:\/\/globex.com\/",
"street" : "Creekside Lane",
"streetNr" : "1a",
"postCode" : "93101",
"country" : "UNITED STATES",
"code" : "AAA001",
"@id" : "http:\/\/example.com\/id\/0001-123456789---SPC_1_1",
"remoteCode" : "0001-123456789---SPC_1_1",
"dateEntryKey" : "606688",
"serviceContractor" : false } } ],
"@context" :
{ "@vocab" : "http:\/\/example.com\/def\/" } }
<http://example.com/graph/AAA000> {
<http://example.com/id/AAA000>
<http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://example.com/def/BUYER> ;
<http://example.com/def/status> <http://example.com/def/RELEASED> ;
<http://example.com/def/duns> 214567885 ;
<http://example.com/def/vatno> "EU826010123" ;
<http://example.com/def/name> "ACME" ;
<http://example.com/def/name2> "Acme Corporation" ;
<http://example.com/def/website> <http://www.acme.com/> ;
<http://example.com/def/street> "Garfield Road" ;
<http://example.com/def/streetNr> "498" ;
<http://example.com/def/postCode> "61611" ;
<http://example.com/def/country> "UNITED STATES" ;
<http://example.com/def/code> "AAA000" ;
<http://example.com/def/remoteCode> "0001-123456789---ACME_1_1" ;
<http://example.com/def/dateEntryKey> 9790294 ;
<http://example.com/def/serviceContractor> false .
}
<http://example.com/graph/AAA001> {
<http://example.com/id/AAA001>
<http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://example.com/def/BUYER> ;
<http://example.com/def/status> <http://example.com/def/RELEASED> ;
<http://example.com/def/duns> 231634267 ;
<http://example.com/def/vatno> "EU826009061" ;
<http://example.com/def/name> "GLOBEX" ;
<http://example.com/def/name2> "Globex Corporation" ;
<http://example.com/def/website> <https://globex.com/> ;
<http://example.com/def/street> "Creekside Lane" ;
<http://example.com/def/streetNr> "1a" ;
<http://example.com/def/postCode> "93101" ;
<http://example.com/def/country> "UNITED STATES" ;
<http://example.com/def/code> "AAA001" ;
<http://example.com/def/remoteCode> "0001-123456789---SPC_1_1" ;
<http://example.com/def/dateEntryKey> 606688 ;
<http://example.com/def/serviceContractor> false .
}
<?xml version="1.0" encoding="UTF-8"?>
<trix:trix xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:trix="http://www.w3.org/2004/03/trix/trix-1/"
xsi:schemaLocation="http://www.w3.org/2004/03/trix/trix-1/ https://www.w3.org/2004/03/trix/trix-1/trix-1.0.xsd">
<trix:graph>
<trix:uri>http://example.com/graph/0001-123456789---ACME_1_1</trix:uri>
<trix:triple>
<trix:uri>http://example.com/id/0001-123456789---ACME_1_1</trix:uri>
<trix:uri>http://www.w3.org/1999/02/22-rdf-syntax-ns#type</trix:uri>
<trix:uri>http://example.com/def/BUYER</trix:uri>
</trix:triple>
<trix:triple>
<trix:uri>http://example.com/id/0001-123456789---ACME_1_1</trix:uri>
<trix:uri>http://example.com/def/status</trix:uri>
<trix:uri>http://example.com/def/RELEASED</trix:uri>
</trix:triple>
<trix:triple>
<trix:uri>http://example.com/id/0001-123456789---ACME_1_1</trix:uri>
<trix:uri>http://example.com/def/duns</trix:uri>
<trix:typedLiteral datatype="http://www.w3.org/2001/XMLSchema#integer">214567885</trix:typedLiteral>
</trix:triple>
<trix:triple>
<trix:uri>http://example.com/id/0001-123456789---ACME_1_1</trix:uri>
<trix:uri>http://example.com/def/vatno</trix:uri>
<trix:plainLiteral>EU826010123</trix:plainLiteral>
</trix:triple>
<trix:triple>
<trix:uri>http://example.com/id/0001-123456789---ACME_1_1</trix:uri>
<trix:uri>http://example.com/def/name</trix:uri>
<trix:plainLiteral>ACME</trix:plainLiteral>
</trix:triple>
<trix:triple>
<trix:uri>http://example.com/id/0001-123456789---ACME_1_1</trix:uri>
<trix:uri>http://example.com/def/name2</trix:uri>
<trix:plainLiteral>Acme Corporation</trix:plainLiteral>
</trix:triple>
<trix:triple>
<trix:uri>http://example.com/id/0001-123456789---ACME_1_1</trix:uri>
<trix:uri>http://example.com/def/website</trix:uri>
<trix:uri>http://www.acme.com/</trix:uri>
</trix:triple>
<trix:triple>
<trix:uri>http://example.com/id/0001-123456789---ACME_1_1</trix:uri>
<trix:uri>http://example.com/def/street</trix:uri>
<trix:plainLiteral>Garfield Road</trix:plainLiteral>
</trix:triple>
<trix:triple>
<trix:uri>http://example.com/id/0001-123456789---ACME_1_1</trix:uri>
<trix:uri>http://example.com/def/streetNr</trix:uri>
<trix:plainLiteral>498</trix:plainLiteral>
</trix:triple>
<trix:triple>
<trix:uri>http://example.com/id/0001-123456789---ACME_1_1</trix:uri>
<trix:uri>http://example.com/def/postCode</trix:uri>
<trix:plainLiteral>61611</trix:plainLiteral>
</trix:triple>
<trix:triple>
<trix:uri>http://example.com/id/0001-123456789---ACME_1_1</trix:uri>
<trix:uri>http://example.com/def/country</trix:uri>
<trix:plainLiteral>UNITED STATES</trix:plainLiteral>
</trix:triple>
<trix:triple>
<trix:uri>http://example.com/id/0001-123456789---ACME_1_1</trix:uri>
<trix:uri>http://example.com/def/code</trix:uri>
<trix:plainLiteral>AAA000</trix:plainLiteral>
</trix:triple>
<trix:triple>
<trix:uri>http://example.com/id/0001-123456789---ACME_1_1</trix:uri>
<trix:uri>http://example.com/def/remoteCode</trix:uri>
<trix:plainLiteral>0001-123456789---ACME_1_1</trix:plainLiteral>
</trix:triple>
<trix:triple>
<trix:uri>http://example.com/id/0001-123456789---ACME_1_1</trix:uri>
<trix:uri>http://example.com/def/dateEntryKey</trix:uri>
<trix:typedLiteral datatype="http://www.w3.org/2001/XMLSchema#integer">9790294</trix:typedLiteral>
</trix:triple>
<trix:triple>
<trix:uri>http://example.com/id/0001-123456789---ACME_1_1</trix:uri>
<trix:uri>http://example.com/def/serviceContractor</trix:uri>
<trix:typedLiteral datatype="http://www.w3.org/2001/XMLSchema#boolean">false</trix:typedLiteral>
</trix:triple>
</trix:graph>
<trix:graph>
<trix:uri>http://example.com/graph/0001-123456789---SPC_1_1</trix:uri>
<trix:triple>
<trix:uri>http://example.com/id/0001-123456789---SPC_1_1</trix:uri>
<trix:uri>http://www.w3.org/1999/02/22-rdf-syntax-ns#type</trix:uri>
<trix:uri>http://example.com/def/BUYER</trix:uri>
</trix:triple>
<trix:triple>
<trix:uri>http://example.com/id/0001-123456789---SPC_1_1</trix:uri>
<trix:uri>http://example.com/def/status</trix:uri>
<trix:uri>http://example.com/def/RELEASED</trix:uri>
</trix:triple>
<trix:triple>
<trix:uri>http://example.com/id/0001-123456789---SPC_1_1</trix:uri>
<trix:uri>http://example.com/def/duns</trix:uri>
<trix:typedLiteral datatype="http://www.w3.org/2001/XMLSchema#integer">231634267</trix:typedLiteral>
</trix:triple>
<trix:triple>
<trix:uri>http://example.com/id/0001-123456789---SPC_1_1</trix:uri>
<trix:uri>http://example.com/def/vatno</trix:uri>
<trix:plainLiteral>EU826009061</trix:plainLiteral>
</trix:triple>
<trix:triple>
<trix:uri>http://example.com/id/0001-123456789---SPC_1_1</trix:uri>
<trix:uri>http://example.com/def/name</trix:uri>
<trix:plainLiteral>GLOBEX</trix:plainLiteral>
</trix:triple>
<trix:triple>
<trix:uri>http://example.com/id/0001-123456789---SPC_1_1</trix:uri>
<trix:uri>http://example.com/def/name2</trix:uri>
<trix:plainLiteral>Globex Corporation</trix:plainLiteral>
</trix:triple>
<trix:triple>
<trix:uri>http://example.com/id/0001-123456789---SPC_1_1</trix:uri>
<trix:uri>http://example.com/def/website</trix:uri>
<trix:uri>https://globex.com/</trix:uri>
</trix:triple>
<trix:triple>
<trix:uri>http://example.com/id/0001-123456789---SPC_1_1</trix:uri>
<trix:uri>http://example.com/def/street</trix:uri>
<trix:plainLiteral>Creekside Lane</trix:plainLiteral>
</trix:triple>
<trix:triple>
<trix:uri>http://example.com/id/0001-123456789---SPC_1_1</trix:uri>
<trix:uri>http://example.com/def/streetNr</trix:uri>
<trix:plainLiteral>1a</trix:plainLiteral>
</trix:triple>
<trix:triple>
<trix:uri>http://example.com/id/0001-123456789---SPC_1_1</trix:uri>
<trix:uri>http://example.com/def/postCode</trix:uri>
<trix:plainLiteral>93101</trix:plainLiteral>
</trix:triple>
<trix:triple>
<trix:uri>http://example.com/id/0001-123456789---SPC_1_1</trix:uri>
<trix:uri>http://example.com/def/country</trix:uri>
<trix:plainLiteral>UNITED STATES</trix:plainLiteral>
</trix:triple>
<trix:triple>
<trix:uri>http://example.com/id/0001-123456789---SPC_1_1</trix:uri>
<trix:uri>http://example.com/def/code</trix:uri>
<trix:plainLiteral>AAA001</trix:plainLiteral>
</trix:triple>
<trix:triple>
<trix:uri>http://example.com/id/0001-123456789---SPC_1_1</trix:uri>
<trix:uri>http://example.com/def/remoteCode</trix:uri>
<trix:plainLiteral>0001-123456789---SPC_1_1</trix:plainLiteral>
</trix:triple>
<trix:triple>
<trix:uri>http://example.com/id/0001-123456789---SPC_1_1</trix:uri>
<trix:uri>http://example.com/def/dateEntryKey</trix:uri>
<trix:typedLiteral datatype="http://www.w3.org/2001/XMLSchema#integer">606688</trix:typedLiteral>
</trix:triple>
<trix:triple>
<trix:uri>http://example.com/id/0001-123456789---SPC_1_1</trix:uri>
<trix:uri>http://example.com/def/serviceContractor</trix:uri>
<trix:typedLiteral datatype="http://www.w3.org/2001/XMLSchema#boolean">false</trix:typedLiteral>
</trix:triple>
</trix:graph>
</trix:trix>
<?xml version="1.0" encoding="UTF-8"?>
<map xmlns="http://www.w3.org/2005/xpath-functions">
<array key="content">
<map>
<string key="type">BUYER</string>
<string key="status">RELEASED</string>
<number key="duns">214567885</number>
<string key="vatno">EU826010123</string>
<string key="name">ACME</string>
<string key="name2">Acme Corporation</string>
<string key="website">http://www.acme.com/</string>
<string key="street">Garfield Road</string>
<string key="streetNr">498</string>
<string key="postCode">61611</string>
<string key="country">UNITED STATES</string>
<string key="code">AAA000</string>
<string key="remoteCode">0001-123456789---ACME_1_1</string>
<number key="dateEntryKey">9790294</number>
<boolean key="serviceContractor">false</boolean>
<null key="companyType"/>
</map>
<map>
<string key="type">BUYER</string>
<string key="status">RELEASED</string>
<number key="duns">231634267</number>
<string key="vatno">EU826009061</string>
<string key="name">GLOBEX</string>
<string key="name2">Globex Corporation</string>
<string key="website">https://globex.com/</string>
<string key="street">Creekside Lane</string>
<string key="streetNr">1a</string>
<string key="postCode">93101</string>
<string key="country">UNITED STATES</string>
<string key="code">AAA001</string>
<string key="remoteCode">0001-123456789---SPC_1_1</string>
<number key="dateEntryKey">606688</number>
<boolean key="serviceContractor">false</boolean>
<null key="companyType"/>
</map>
</array>
<map key="pageable">
<number key="offset">0</number>
<map key="sort">
<boolean key="sorted">true</boolean>
<boolean key="unsorted">false</boolean>
<boolean key="empty">false</boolean>
</map>
<number key="pageSize">2</number>
<number key="pageNumber">0</number>
<boolean key="paged">true</boolean>
<boolean key="unpaged">false</boolean>
</map>
<boolean key="last">false</boolean>
<number key="totalPages">10</number>
<number key="totalElements">20</number>
<map key="sort">
<boolean key="sorted">true</boolean>
<boolean key="unsorted">false</boolean>
<boolean key="empty">false</boolean>
</map>
<boolean key="first">true</boolean>
<number key="numberOfElements">2</number>
<number key="size">2</number>
<number key="number">0</number>
<boolean key="empty">false</boolean>
</map>
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="3.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:fn="http://www.w3.org/2005/xpath-functions" exclude-result-prefixes="fn xs xsl">
<xsl:output method="text" encoding="utf-8"/>
<xsl:param name="filename" as="xs:string" select="'companies.json'"/>
<xsl:variable name="encoding" as="xs:string" select="'utf-8'"/>
<xsl:variable name="json" select="unparsed-text($filename, $encoding)"/>
<xsl:variable name="doc" select="json-to-xml($json)"/>
<xsl:variable name="graph" select="'http://example.com/graph/'"/>
<xsl:variable name="base" select="'http://example.com/id/'"/>
<xsl:variable name="vocab" select="'http://example.com/def/'"/>
<xsl:variable name="context">
<fn:map key="@context">
<fn:string key="@vocab">
<xsl:value-of select="$vocab"/>
</fn:string>
</fn:map>
</xsl:variable>
<xsl:template name="json-to-jsonld">
<xsl:variable name="xml">
<xsl:apply-templates select="$doc"/>
</xsl:variable>
<xsl:value-of select="xml-to-json($xml, map{'indent':true()})"/>
</xsl:template>
<xsl:template match="/fn:map">
<fn:map>
<xsl:apply-templates select="fn:array[@key='content']"/>
<xsl:copy-of select="$context"/>
</fn:map>
</xsl:template>
<xsl:template match="fn:array[@key='content']">
<fn:array key="@graph">
<xsl:apply-templates/>
</fn:array>
</xsl:template>
<xsl:template match="fn:array[@key='content']/fn:map">
<fn:map>
<fn:string key="@id">
<xsl:value-of select="concat($graph, fn:string[@key='remoteCode'])"/>
</fn:string>
<fn:map key="@graph">
<xsl:apply-templates/>
</fn:map>
</fn:map>
</xsl:template>
<xsl:template match="fn:string[@key='remoteCode']">
<fn:string key="@id">
<xsl:value-of select="concat($base, .)"/>
</fn:string>
<xsl:copy-of select="."/>
</xsl:template>
<xsl:template match="fn:string[@key='type']">
<fn:string key="@type">
<xsl:value-of select="concat($vocab, .)"/>
</fn:string>
<xsl:copy-of select="."/>
</xsl:template>
<xsl:template match="fn:number[@key='dateEntryKey']">
<fn:string key="dateEntryKey">
<xsl:value-of select="xs:string(.)"/>
</fn:string>
</xsl:template>
<xsl:template match="fn:number[@key='duns']">
<fn:string key="duns">
<xsl:value-of select="xs:string(.)"/>
</fn:string>
</xsl:template>
<xsl:template match="fn:string|fn:number|fn:boolean">
<xsl:copy-of select="."/>
</xsl:template>
</xsl:stylesheet>
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="3.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:fn="http://www.w3.org/2005/xpath-functions" xmlns:trix="http://www.w3.org/2004/03/trix/trix-1/" exclude-result-prefixes="fn xs xsl">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes" expand-text="yes"/>
<xsl:param name="filename" as="xs:string" select="'companies.json'"/>
<xsl:variable name="encoding" as="xs:string" select="'utf-8'"/>
<xsl:variable name="json" select="unparsed-text($filename, $encoding)"/>
<xsl:variable name="doc" select="json-to-xml($json)"/>
<xsl:variable name="graph" select="'http://example.com/graph/'"/>
<xsl:variable name="base" select="'http://example.com/id/'"/>
<xsl:variable name="vocab" select="'http://example.com/def/'"/>
<xsl:template name="json-to-xml">
<xsl:apply-templates select="$doc"/>
</xsl:template>
<xsl:template match="/">
<trix:trix xsi:schemaLocation="http://www.w3.org/2004/03/trix/trix-1/ https://www.w3.org/2004/03/trix/trix-1/trix-1.0.xsd">
<xsl:apply-templates/>
</trix:trix>
</xsl:template>
<xsl:template match="/fn:map">
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="fn:array[@key='content']">
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="fn:array[@key='content']/fn:map">
<xsl:variable name="slug" select="fn:string[@key='remoteCode']"/>
<trix:graph>
<trix:uri>
<xsl:value-of select="concat($graph, $slug)"/>
</trix:uri>
<xsl:apply-templates mode="triple">
<xsl:with-param name="s" select="concat($base, $slug)"/>
</xsl:apply-templates>
</trix:graph>
</xsl:template>
<!-- specific templates matching keys -->
<xsl:template match="fn:string[@key='website']" mode="triple">
<xsl:param name="s"/>
<xsl:call-template name="spo">
<xsl:with-param name="s" select="$s"/>
<xsl:with-param name="p" select="concat($vocab, @key)"/>
<xsl:with-param name="o" select="."/>
</xsl:call-template>
</xsl:template>
<xsl:template match="fn:string[@key='type']" mode="triple">
<xsl:param name="s"/>
<xsl:call-template name="spo">
<xsl:with-param name="s" select="$s"/>
<xsl:with-param name="p" select="'http://www.w3.org/1999/02/22-rdf-syntax-ns#type'"/>
<xsl:with-param name="o" select="concat($vocab, .)"/>
</xsl:call-template>
</xsl:template>
<xsl:template match="fn:string[@key='status']" mode="triple">
<xsl:param name="s"/>
<xsl:call-template name="spo">
<xsl:with-param name="s" select="$s"/>
<xsl:with-param name="p" select="concat($vocab, @key)"/>
<xsl:with-param name="o" select="concat($vocab, .)"/>
</xsl:call-template>
</xsl:template>
<!-- generic templates for values -->
<xsl:template match="fn:string" mode="triple">
<xsl:param name="s"/>
<xsl:call-template name="spv">
<xsl:with-param name="s" select="$s"/>
<xsl:with-param name="p" select="concat($vocab, @key)"/>
<xsl:with-param name="v" select="."/>
</xsl:call-template>
</xsl:template>
<xsl:template match="fn:number[matches(., '^[0-9]*$')]" mode="triple">
<xsl:param name="s"/>
<xsl:call-template name="spvd">
<xsl:with-param name="s" select="$s"/>
<xsl:with-param name="p" select="concat($vocab, @key)"/>
<xsl:with-param name="v" select="."/>
<xsl:with-param name="d" select="'http://www.w3.org/2001/XMLSchema#integer'"/>
</xsl:call-template>
</xsl:template>
<xsl:template match="fn:number[matches(., '^[0-9]*\.[0-9]*$')]" mode="triple">
<xsl:param name="s"/>
<xsl:call-template name="spvd">
<xsl:with-param name="s" select="$s"/>
<xsl:with-param name="p" select="concat($vocab, @key)"/>
<xsl:with-param name="v" select="."/>
<xsl:with-param name="d" select="'http://www.w3.org/2001/XMLSchema#decimal'"/>
</xsl:call-template>
</xsl:template>
<xsl:template match="fn:boolean" mode="triple">
<xsl:param name="s"/>
<xsl:call-template name="spvd">
<xsl:with-param name="s" select="$s"/>
<xsl:with-param name="p" select="concat($vocab, @key)"/>
<xsl:with-param name="v" select="."/>
<xsl:with-param name="d" select="'http://www.w3.org/2001/XMLSchema#boolean'"/>
</xsl:call-template>
</xsl:template>
<!-- named templates for triples -->
<xsl:template name="spv">
<xsl:param name="s"/>
<xsl:param name="p"/>
<xsl:param name="v"/>
<trix:triple>
<trix:uri>
<xsl:value-of select="$s"/>
</trix:uri>
<trix:uri>
<xsl:value-of select="$p"/>
</trix:uri>
<trix:plainLiteral>
<xsl:value-of select="$v"/>
</trix:plainLiteral>
</trix:triple>
</xsl:template>
<xsl:template name="spvd">
<xsl:param name="s"/>
<xsl:param name="p"/>
<xsl:param name="v"/>
<xsl:param name="d"/>
<trix:triple>
<trix:uri>
<xsl:value-of select="$s"/>
</trix:uri>
<trix:uri>
<xsl:value-of select="$p"/>
</trix:uri>
<trix:typedLiteral datatype="{$d}">
<xsl:value-of select="$v"/>
</trix:typedLiteral>
</trix:triple>
</xsl:template>
<xsl:template name="spo">
<xsl:param name="s"/>
<xsl:param name="p"/>
<xsl:param name="o"/>
<trix:triple>
<trix:uri>
<xsl:value-of select="$s"/>
</trix:uri>
<trix:uri>
<xsl:value-of select="$p"/>
</trix:uri>
<trix:uri>
<xsl:value-of select="$o"/>
</trix:uri>
</trix:triple>
</xsl:template>
<!-- ignore all other elements and attributes -->
<xsl:template match="*|@*"/>
<xsl:template match="*|@*" mode="triple"/>
</xsl:stylesheet>
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="3.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:fn="http://www.w3.org/2005/xpath-functions" exclude-result-prefixes="fn xs xsl">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes" expand-text="yes"/>
<xsl:param name="filename" as="xs:string" select="'companies.json'"/>
<xsl:variable name="encoding" as="xs:string" select="'utf-8'"/>
<xsl:variable name="json" select="unparsed-text($filename, $encoding)"/>
<xsl:template name="json-to-xml">
<xsl:copy-of select="json-to-xml($json)"/>
</xsl:template>
</xsl:stylesheet>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment