10.2.4 Core Query Language
This clause defines a subset of SDQL.  In addition to the procedures defined in this clause, the current-node, node-list-empty?, node-list?, parent, and node-list-error procedures are allowed in the subset.  This subset is designed so that a node-list never contains more than one node and so that any node that it does contain is always of type element.
In the following procedures, the argument that is of type node-list can be omitted and defaults to (current-node).  osnl (optional singleton node-list) denotes an argument that shall be a node-list containing zero or one nodes.
10.2.4.1 Navigation
(ancestor string osnl)
Returns a node-list containing the nearest ancestor of osnl with a gi equal to string, or an empty node-list if there is no such ancestor or if osnl is empty.
(gi osnl)
Returns the value of the gi property of the node contained in osnl or #f if osnl is empty or if osnl has no gi property or a null gi property.
(first-child-gi osnl)
Returns the value of the gi property of the first child of osnl of class element or #f if osnl is empty or has no such child.
(id osnl)
Returns the value of the id property of the node contained in osnl or #f if osnl is empty or if osnl has no id property or a null id property.
10.2.4.2 Counting
(child-number snl)
Returns the child number of snl.  The child number of an element is one plus the number of element siblings of the current element that precede in tree order the current element and that have the same generic identifier as the current element.
(ancestor-child-number string snl)
Returns the child number of the nearest ancestor of snl whose generic identifier is string, or #f if there is no such ancestor.
(hierarchical-number list snl)
Returns a list of non-negative integers with the same number of members as list.  list shall be a list of strings.  The last member is the child number of the nearest ancestor of snl whose generic identifier is equal to the last member of list, the next to last member is the child number of the nearest ancestor of that element whose generic identifier is equal to the next to last member, and so on for each member of list.
(hierarchical-number-recursive string snl)
Returns a list of non-negative integers. The last member of the list is the child number of the nearest ancestor of the snl element whose generic identifier is equal to string, the next to last member is the child number of the nearest ancestor of that element whose generic identifier is equal to string, and so on for each ancestor of the current element with generic identifier equal to string.  Note that the length of this list is the nesting level of string.
(element-number snl)
Returns the number of elements before or equal to snl with the same gi as snl.
(element-number-list list snl)
Returns a list of non-negative integers, one for each member of list, which shall be a list of strings, where the i-th integer is the number of elements that:

•  are before or equal to snl,

•  have a generic identifier equal to the i-th member of list, and

•  if i is greater than 1, are after the last element before snl whose generic identifier is equal to the i-1th member of list.
In effect the counter for each argument is reset at the start of the element referred to by the previous argument.
An element is considered to be after its parent.
This procedure could be used to number footnotes sequentially within a chapter (by using the last number in the list). It could also be used to number headings in a document whose DTD lacks container elements.
10.2.4.3 Accessing Attribute Values
In the following procedures, attribute values are represented as strings by applying the data procedure to the attribute-assignment node.
(attribute-string string osnl)
Returns a string representation of the attribute with name equal to string of osnl, or #f if osnl has no such attribute, or the attribute is implied, or osnl is empty.
(inherited-attribute-string string osnl)
Returns a string representation of the attribute with name equal to string of osnl or of the nearest ancestor of osnl for which this attribute is present and not implied, or #f if there is no such element or osnl is empty.  For the purpose of this procedure, a node is considered an ancestor of itself.
(inherited-element-attribute-string string1 string2 osnl )
Returns a string representation of the attribute with name equal to string2 of the nearest ancestor of osnl whose generic identifier is equal to string1 and for which this attribute is present and not implied, or #f if there is no such element or osnl is empty.  For the purpose of this procedure, a node is considered an ancestor of itself.
10.2.4.4 Testing Current Location
(first-sibling? snl)
Returns #t if snl has no preceding sibling that is an element with the same generic identifier as itself, and otherwise returns #f.
(absolute-first-sibling? snl)
Returns #t if snl has no preceding sibling that is an element, and otherwise returns #f.
(last-sibling? snl)
Returns #t if snl has no following sibling that is an element with the same generic identifier as itself, and otherwise returns #f.
(absolute-last-sibling? snl)
Returns #t if snl has no following sibling that is an element, and otherwise returns #f.
(have-ancestor? obj snl)
obj shall be either a string or a list of strings.  If obj is a string, then have-ancestor? returns #t if snl has an ancestor with a generic identifier that matches that string and otherwise returns #f.  If obj is a list of strings, then have-ancestor? returns #t if snl has an ancestor with generic identifier equal to the last member of obj, which itself has an ancestor with generic identifier equal to the next to last member of obj, and so on for each member, and otherwise returns #f.
10.2.4.5 Entities and Notations
snl here determines the document in which to find the entity.
(entity-public-id string snl)
Returns the value of the public-id property of the value of the external-id property of the general entity whose name is string in the governing document type of the same grove as snl, or #f if there is no such entity or the entity has a null value for the external-id property or the external-id has a null value for the public-id property.
(entity-system-id string snl)
Returns the value of the system-id property of the value of the external-id property of the general entity whose name is string in the governing document type of the same grove as snl, or #f if there is no such entity or the entity has a null value for the external-id property or the external-id has a null value for the system-id property.
(entity-generated-system-id string snl)
Returns the value of the generated-system-id property of the value of the external-id property of the general entity whose name is string in the governing document type of the same grove as snl, or #f if there is no such entity or the entity has a null value for the external-id property or the external-id has a null value for the generated-system-id property.
(entity-text string snl)
Returns the value of the text property of the general entity whose name is string in the governing document type of the same grove as snl, or #f if there is no such entity or the entity has a null value for the text property.
(entity-notation string snl)
Returns the value of the notation-name property of the general entity whose name is string in the governing document type of the same grove as snl, or #f if there is no such entity or the entity has a null value for the notation-name property.
(entity-attribute-string string1 string2 snl)
Returns a string representation of the value of the attribute named string2 of the general entity whose name is string1 in the governing document type of the same grove as snl, or #f if there is no such entity or the entity has no such attribute or the attribute is implied.
(entity-type string snl)
Returns the value of the entity-type property of the general entity whose name is string in the governing document type of the same grove as snl, or #f if there is no such entity or the entity has a null value for the entity-type property.
(notation-public-id string snl)
Returns the value of the public-id property of the value of the external-id property of the general notation whose name is string in the governing document type of the same grove as snl, or #f if there is no such notation or the external-id has a null value for the public-id property.
(notation-system-id string snl)
Returns the value of the system-id property of the value of the external-id property of the general notation whose name is string in the governing document type of the same grove as snl, or #f if there is no such notation or the external-id has a null value for the system-id property.
(notation-generated-system-id string snl)
Returns the value of the generated-system-id property of the value of the external-id property of the general notation whose name is string in the governing document type of the same grove as snl, or #f if there is no such notation or the external-id has a null value for the generated-system-id property.
10.2.4.6 Name Normalization
(general-name-normalize string snl)
Returns string transformed using the general namecase substitution string normalization rule of the grove in which snl occurs. This could be defined as follows:
(define (general-name-normalize string snl)
  (named-node-list-normalize string
                             (node-property 'elements (grove-root snl))
                             'element))
(entity-name-normalize string snl)
Returns string transformed using the entity namecase substitution string normalization rule of the grove in which snl occurs. This could be defined as follows:
(define (entity-name-normalize string snl)
  (named-node-list-normalize string
                             (node-property 'entities (grove-root snl))
                             'entity))