你可以做到。目前我的公司使用 eXist-db 来做这件事,但同样的规则也适用于 BaseX、Sedna 或 Marklogic。
您必须掌握 XPath 2.0 并了解一点 XQuery,并避免进行特定于命名空间的查询。
我认为您需要从 XBRL 实例文档中查询数据。这可以分两步完成:
1.获取你要查询的context id
2. 在这个上下文中搜索事实元素
这个查询可以通过一次调用来完成:
xquery version "3.0";
declare default element namespace"http://www.xbrl.org/2003/instance";
declare function local:for-context($node as node(),$ent as xs:string,$start as xs:string,$end as xs:string) as xs:boolean {
let $cid := $node/@contextRef
let $ctx := $node/../context[ @id = $cid ]
return if ( $ctx
and not(exists($ctx/entity/segment))
and $ctx/entity/identifier=$ent
and $ctx/period/startDate=$start
and $ctx/period/endDate=$end ) then true() else false()
};
let $id := request:get-parameter( 'id', '0001173514' )
let $startDate := request:get-parameter( 'startdate', '2013-04-01' )
let $endDate := request:get-parameter( 'enddate', '2013-06-30' )
let $fact := request:get-parameter( 'fact', 'NonoperatingIncomeExpense' )
let $q := concat( "/*/*:", $fact, "[ local:for-context(., $id, $startDate, $endDate) ]" )
return util:eval($q)
它接收公司 ID、开始日期、结束日期和事实名称,并从实例文档中返回值。