Skip to content

Instantly share code, notes, and snippets.

@wcandillon
Created October 19, 2014 16:40
Show Gist options
  • Save wcandillon/c9eaed1e9e9762a6b9a8 to your computer and use it in GitHub Desktop.
Save wcandillon/c9eaed1e9e9762a6b9a8 to your computer and use it in GitHub Desktop.
Convert a fact to OData
declare function conversion:facts-to-odata($facts as object*) as node()*
{
for $f at $y in $facts
return
<entry xmlns='http://www.w3.org/2005/Atom'
xmlns:m='http://schemas.microsoft.com/ado/2007/08/dataservices/metadata'
xmlns:d='http://schemas.microsoft.com/ado/2007/08/dataservices'
xml:base='http://www.xbrlsite.com/2014/Demos/OData/SECXBRLinfo.svc/'>
<id>{"http://secxbrl.info/odata/" || current-date() || "/" || $y}</id>
<category term='SEC.FundamentalAccountingConcepts' scheme='http://schemas.microsoft.com/ado/2007/08/dataservices/scheme'/>
<link rel='edit' title='{$f.EntityRegistrantName}' href='{"UKFacts" || $y}'/>
<title>{$f.EntityRegistrantName}</title>
<updated>{current-dateTime()}</updated>
<author><name>secxbrl.info</name></author>
<content type='application/xml'>
<m:properties>{
element {"d:Value"} { attribute { "m:type" } {
switch ($f.type)
case "NumericValue" return "Edm.Int64"
case "BooleanValue" return "Edm.Boolean"
case "StringValue" return "Edm.String"
default return "Edm.Int16"
}, $f.Value },
<d:EntityRegistrantName>{$f.EntityRegistrantName}</d:EntityRegistrantName>,
for $k in keys($f.Aspects)
return
element { "d:" || substring-after($k, ":") } { $f.Aspects.$k }
}</m:properties>
</content>
</entry>
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment