-
Notifications
You must be signed in to change notification settings - Fork 16
Finding a node
Although it is possible to navigate a hierarchy using the recursive method this method is most suited to tasks that affect all or a substantial proportion of the nodes. It is not an ideal method when the requirement is to find a specific node because on average half of all the nodes must be traversed to find the one.
This is OK when there are a small number of nodes or if only one node need to be retrieved. But if the requirement is to find a succession of nodes, perhaps scattered throughout the hierarchy, then search half of all the nodes each time is not efficient.
Instead, compiled taxonomies include an index that allows a caller to locate a node in a the hierarchy more efficiently because the algorithm used to find the node is not affected by the size of the hierarcy.
Below is an example of using the path to locate rows. Of course the first thing is to access a taxonomy that includes some form of hierarchy such as a presentation linkbase:
$xbrl = \XBRL::load_taxonomy( '<some file>' );
Now the presentation roles can be accessed.
$roles = $xbrl->getPresentationRoleRefs();
This is the label of the node to be found.
$id = 'uk-gaap_ShareholderFunds';
There are many ways to tack the next step. In this case it is to create a list of paths. The element could exist in several roles. For example, in the UK GAAP taxonomy the shareholder funds element appears in the balance sheet role (twice) and in the reconciliation of shareholder funds role (also twice).
$locatedPaths = array_reduce( $roles, function( $carry, $role ) use( $id ) {
if ( ! isset( $role['paths'] ) ) return $carry;
if ( ! isset( $role['paths'][ $id ] ) ) return $carry;;
$carry[ $role['roleUri'] ] = $role['paths'][ $id ];
return $carry;
}, array() );
Now find and process each node. $locatedPaths is an array of arrays.
foreach ( $locatedPaths as $roleKey => $paths )
{
foreach ( $paths as $key => $path )
{
The function $xbrl->processNode() is able to take a path and find the corresponding node in a set of nodes in a hierarchy.
- @param array $nodes A set of $node arrays
- @param string $path The path to the element in the $node hierarchy
- @param function $callback If supplied this will be called once for every node located.
- @return bool True if the element is found
$success = $xbrl->processNode( $roles[ $roleKey ]['hierarchy'], $path, function( &$node ) {
$node['yyy'] = 'zzz';
} );
}
}
The callback receives the node as a reference parameter. This means the callback is able to modify the hierarchy node.
Copyright © 2021 and later years Lyquidity Solutions Limited
- About us
- Purpose
- XBRL support
- Road Map
- Why PHP?
- Contributing
- License
- Reference links
- Case Study
- Digital Financial Reporting
- Digital Financial Reporting examples
Overview
Class and function reference
Compiled taxonomy structure
Common arrays
Compiling
Compiling
Processing linkbases
Additional taxonomy processing
Extension taxonomies
Compiled taxonomy folder
How do I...?
Navigate a node tree
Find a node in a tree
Find elements in a taxonomy
Load an instance document
Find elements in an instance
Create a simple report
Create a comparison report
Example custom report
Work with dimensions
Sign and Verify
Validate
Change the logging
Capture validation information