240 likes | 378 Views
Using XQuery to process XBRL. Ignacio Hernández-Ros Technology development XBRL International. Using XQuery to process XBRL. What’s XQuery? What’s the relationship between XBRL and XQuery? Using the XBRL functions library. 8’ 10’ 8’. What’s XQuery. 1. XQuery is a W3C standard
E N D
Using XQuery to process XBRL Ignacio Hernández-Ros Technology development XBRL International
Using XQuery to process XBRL • What’s XQuery? • What’s the relationship between XBRL and XQuery? • Using the XBRL functions library 8’ 10’ 8’
What’s XQuery 1 • XQuery is a W3C standard • http://www.w3.org/TR/xquery/ • The status is Candidate Release 3 Nov. 2005 • XQuery is an extension of XPath 2.0 • Defines semantics about processing XML information • Is not related to any database or storage system
What’s XQuery 1 • But … the most important thing is how XQuery gives you productivity • Notes: • XQuery is not so powerful as the other programming languages. • XQuery execution performance is comparable with scripts over compiled programming languages. • XQuery development requires deep XML knowledge and related technologies like XPath 2.0 Development effort C/C++ Java/.net XQuery
What’s XQuery 1 • Comparing XQuery with XPath 2.0 • Both have more things in common than differences. • A way to do the research is to look at the differences in the processing model of both languages.
What is XQuery 1 • XQuery over XPath 2.0 Find the 3 differences XPath 2.0 XQuery
What is XQuery 1 • 3 – XQuery query prolog supports parameterization of the execution engine XPath 2.0 XQuery
What is XQuery 1 • 1 – XQuery supports modules and modules contains functions • Functions encapsulate the XQuery complexity from the business side • Modules may be stored in web servers XPath 2.0 XQuery
What is XQuery 1 • 2 – XQuery supports XML Schema type checking and validation XPath 2.0 XQuery
What is XQuery 1 • So, XQuery supports: • modules and • strong XML schema validation. • Plus a uniform platform to access/execute the code. • These two characteristics make XQuery a powerful language to process XML/XBRL infosets.
What’s the relationship between XBRL and XQuery? 2 • Is there any relationship? • NOT YET • If there were relationships, what might they be? • The Formula linkbase already uses XPath 2.0 • XPath 2.0 can use functions defined in XQuery modules • A linkbase may declare the XQuery modules where the required functions are defined
What’s the relationship between XBRL and XQuery? 2 Labels lb XBRL Taxonomy Reference lb Presentation lb Calculation lb Definition lb
What’s the relationship between XBRL and XQuery? 2 Labels lb XBRL Taxonomy Reference lb Presentation lb Calculation lb Definition lb Formula lb
What’s the relationship between XBRL and XQuery? 2 Labels lb XBRL Taxonomy Reference lb Presentation lb Calculation lb Definition lb Functions module Functions module Functions modules Formula lb
What’s the relationship between XBRL and XQuery? 2 Functions module Functions module Functions modules Formula lb • Should contain: • Locators to taxonomy concepts • Resources of multiple types • References to modules • Constants definitions • Variable definitions • Business side of the formula • Arcs • Linking all together • Should contain: • Other modules • Other XML Schemas • IT side of the formula • This is, the real formula implementation for any XBRL element regardless of the taxonomy in use
What’s the relationship between XBRL and XQuery? 2 Functions module Functions module Functions modules Formula lb Example(*): Example(*): <formulaLinkxlink:type="extended"xlink:role="http://www.xbrl.org/2003/role/link"> <modulexlink:type="resource"namespace="http://xbrl.org/2006/functions"uri="http://www.xbrl.org/2006/functions/xf-2006.xq"prefix="xfi"/> <link:locVariablexlink:type="locator"xlink:label="item1"xlink:href="TaxonomySchema.xsd#Cash"name="Cash"/> <link:locVariablexlink:type="locator"xlink:label="item2" xlink:href="TaxonomySchema.xsd#IncreaseDecreaseInCash"name="ChangesInCash"/> <formulaxlink:type="resource"xlink:label="movementAnalisys"select="xfi:CheckMovement($Cash,$ChangesInCash,P3M)"/> </formulaLink> xquery version “1.0”; module namespace xfi = “http://xbrl.org/2006/functions”; import schema namespace xl = "http://www.xbrl.org/2003/XLink"at"http://www.xbrl.org/2003/xl-2003-12-31.xsd"; declare function xfi:CheckMovement($instantVar as schema-element(xbrli:item),$durationVar as schema-element(xbrli:item), $period as xdt:yearMonthDuration) as boolean { if (…) then true() else false() }; (*) Examples do not represent the syntax of the XII formula linkbase (under development)
What’s the relationship between XBRL and XQuery? 2 Functions module Functions module Functions modules Formula lb Example(*): Example(*): <formulaLinkxlink:type="extended"xlink:role="http://www.xbrl.org/2003/role/link"> <modulexlink:type="resource"namespace="http://xbrl.org/2006/functions"uri="http://www.xbrl.org/2006/functions/xf-2006.xq"prefix="xfi"/> <link:locVariablexlink:type="locator"xlink:label="item1"xlink:href="TaxonomySchema.xsd#Cash"name="Cash"/> <link:locVariablexlink:type="locator"xlink:label="item2" xlink:href="TaxonomySchema.xsd#IncreaseDecreaseInCash"name="ChangesInCash"/> <formulaxlink:type="resource"xlink:label="movementAnalisys"select="xfi:CheckMovement($Cash,$ChangesInCash,P3M)"/> </formulaLink> xquery version “1.0”; module namespace xfi = “http://xbrl.org/2006/functions”; import schema namespace xl = "http://www.xbrl.org/2003/XLink"at"http://www.xbrl.org/2003/xl-2003-12-31.xsd"; declare function xfi:CheckMovement($instantVar as schema-element(xbrli:item),$durationVar as schema-element(xbrli:item), $period as xdt:yearMonthDuration) as boolean { if (…) then true() else false() }; Formula processors would be free to use the XQuery version of the function or a local (faster) version (*) Examples do not represent the syntax of the XII formula linkbase (under development)
What’s the relationship between XBRL and XQuery? 2 • Tools will hide the complexity of the formula linkbase in the business side. • Functions should be developed by people that: • Understand XBRL • Understand XQuery • Some might be written by the XII Spec WG • Functions are reusable material between taxonomies
Using the XBRL functions library 3 • During the development of the formula/functions XBRL specification, a set of functions to work with XBRL has been defined (IWD of the spec WG) • Those functions will be part of the final XBRL functions specification • All of those functions are now implemented in an XQuery module (xfi) “xf-2006.xq” as a “Proof of Concept”
Using the XBRL functions library 3 • That XQuery module can be used to • Learn XQuery and how XQuery can process XBRL • Develop higher level functions • For testing instance document content • For transforming instance documents • For providing feedback to the Spec WG • …
Using the XBRL functions library 3 • Yes but how can I do that? • You need: • An XQuery processor (e.g., Altova XML Spy, Saxon, …) • A sample instance document • XQuery code written by you XQuery processor XBRL Instance Output XML Your XQuery XII XQuery Module
Using the XBRL functions library 3 • Function blocks: • Accessor functions: provide access to content in the instance document. Contexts, units, periods, segments, entities, facts, tuples etc. • Constructor functions: allow dynamic creation of instance documents • Taxonomy functions: allow navigation throw the taxonomy and linkbases • Utility functions: files in the DTS etc…
Using the XBRL functions library 3 • They are ‘low level’ functions • Required to start building ‘high level’ functions • Running the example …