This page was generated
January  28,  2016
4:04  AM
XQuery & XSLT Built-In & Modules Function Reference

Built-In: Schema

The schema component built-in functions.
Function Summary
sc:annotations Returns the schema annotations of the component, if any.
sc:attribute-decl Returns the attribute declaration of item, as a schema component, if any.
sc:attributes Returns the attribute declarations of the schema component, if any.
sc:canonical-path Returns the canonical schema component path of the component.
sc:complex-type Returns the complex type of item, as a schema component, if any.
sc:component-property Returns the named property of the schema component.
sc:element-decl Returns the element declaration of item, as a schema component, if any.
sc:facets Returns the facets of the component, if any.
sc:function-parameter-type Returns the declared parameter type of a specific parameter of the function item as a schema component.
sc:function-return-type Returns the return type of a function item as a schema component.
sc:name Returns the name of the schema component, if any.
sc:particles Returns the particles of the schema component, if any.
sc:schema Returns the root schema of the item.
sc:schema-from-path Get a schema object as a value based on its namespace and schema location hint.
sc:simple-type Returns the simple type of item, as a schema component, if any.
sc:type Returns the type of item, as a schema component, if any.
sc:type-apply Apply a type to an item to construct a typed instance of that type.
sc:type-named Returns the type with the given name, if any, as a schema component.
Function Detail
sc:annotations(
[$arg as schema-component()]
)  as   element()*
Summary:

Returns the schema annotations of the component, if any. The context item is used if no argument is given.

Annotations will only be returned for schemas that have preservation of them enabled with the "xdmp-annotations" processing instruction. The annotations returned will only include the appinfo children of the annotations unless the schema has the "all" parameter set in the "xdmp-annotations" processing instruction.


Parameters:
$arg (optional): The item whose annotations are to be returned.

Example:
<?xdmp-annotations?> <!-- Preserve annotations -->
<?xdmp-annotations all?> <!-- Preserve documentation annotations -->
Example:
declare namespace ex="http://example.com/dummy";
declare namespace app="http://example.com/appinfo";

doc("example.xml")/ex:root/*[1]/sc:element-decl()!sc:annotations()/app:hidden
  =>
false()

sc:attribute-decl(
[$arg as item()]
)  as   attribute-decl()?
Summary:

Returns the attribute declaration of item, as a schema component, if any. If the item has no attribute declaration, the empty sequence is returned. The context item is used if no argument is given.

  • If the item is an attribute node, the result is of its attribute declaration.
  • In other cases, the result is the empty sequence.

Parameters:
$arg (optional): The item whose attribute declaration is to be returned.

Example:
declare namespace xh="http://www.w3.org/1999/xhtml";

<decl>{sc:attribute-decl(
  <html xmlns="http://www.w3.org/1999/xhtml">
    <head><title>Example</title></head>
    <body><p class="example">Example</p></body>
  </html>//xh:p/@class)}</decl>;

  =>
<decl><xs:attribute name="class" type="xs:NMTOKENS" xmlns:xs="http://www.w3.org/2001/XMLSchema"/></decl>

sc:attributes(
[$arg as schema-component()]
)  as   attribute-decl()*
Summary:

Returns the attribute declarations of the schema component, if any. The context item is used if no argument is given.


Parameters:
$arg (optional): The item whose attribute declarations are to be returned.

Example:
declare namespace xh="http://www.w3.org/1999/xhtml";

<html xmlns="http://www.w3.org/1999/xhtml">
<head><title>Example</title></head>
<body><p><a id="a1">Example</a></p></body>
</html>/sc:element-decl()!sc:attributes()
  =>
@version
@xml:lang

sc:canonical-path(
[$arg as schema-component()]
)  as   xs:string?
Summary:

Returns the canonical schema component path of the component. See http://www.w3.org/TR/xmlschema-ref/ for the definition of this path. The context item is used if no argument is given.


Parameters:
$arg (optional): The schema component whose canonical path is to be returned.

Example:
sc:canonical-path(sc:type(47))
  => "/type::p1:integer"

sc:complex-type(
[$arg as item()]
)  as   complex-type()?
Summary:

Returns the complex type of item, as a schema component, if any. If the item has a simple type rather than a complex type, the empty sequence is returned. The context item is used if no argument is given.

  • If the item is a document node, the result is the complex type of its root element.
  • If the item is an element node, the result is the complex type of its element declaration.
  • If the item is a schema component, the result is the associated complex type schema component.
  • In other cases, the result is the empty sequence.

Parameters:
$arg (optional): The item whose simple type is to be returned.

Example:
xdmp:describe(sc:complex-type(47))
  => ()

sc:component-property(
$propname as xs:string,
[$arg as schema-component()]
)  as   item()*
Summary:

Returns the named property of the schema component. The context item is used for the second argument if it is not given.

Properties include:

name
Same as sc:name
type
Same as sc:type
complex-type
Same as sc:complex-type
simple-type
Same as sc:simple-type
element-decl
Same as sc:element-decl
attribute-decl
Same as sc:attribute-decl
schema
Same as sc:schema
annotations
Same as sc:annotations
facets
Same as sc:facets
attributes
Same as sc:attributes
particles
Same as sc:particles
attribute-groups
The attribute groups of the schema
model-groups
The model groups of the schema
notations
The notations of the schema
types
The types of the schema
elements
The element declarations of the schema
attribute-wildcard
The attribute wildcard on the type or in the attribute group
identity-constraints
The identity constraints on the element declaration or schema
scope
The scope of the element or attribute declaration
fixed
The fixed value of the element or attribute declaration or whether a facet is fixed
default
The default value of the element or attribute declaration
substitution-group
The element declaration serving as the substitution group head of the element declaration
nillable
Whether the element declaration is declared as nillable
abstract
Whether the element declaration or type is declared as abstract
block-extension
Whether the element declaration or complex type is declared as blocking extensions
block-restriction
Whether the element declaration or complex type is declared as blocking restrictions
block-substitution
Whether the element declaration is declared as blocking substitutions
final-extension
Whether the element declaration or complex type is declared as final for extensions
final-restriction
Whether the element declaration or complex type is declared as final for restrictions
variety
The variety of the simple type (atomic, list, or union)
base
The base type of the type
primitive
The primitive type of the simple type
item-type
The item type of the list simple type
member-types
The member types of the union simple type
ordered
The ordering of the simple type
numeric
Whether the simple type is numeric
finite
Whether the simple type is finite
bounded
Whether the simple type is bounded
final-list
Whether the simple type is declared as final for lists
final-union
Whether the simple type is declared as final for unions
final-restriction
Whether the simple type is declared as final for restrictions
derivation-method
The derivation method of the complex type (extension, restriction)
content-type
The kind of content type of the complex type (empty, simple, element-only, mixed)
min-occurs
The declared minimum occurrences of the particle
max-occurs
The declared maximum occurrences of the particle
process-contents
What processing is declared for the wildcard (strict, lax, skip)
namespaces
What namespaces the wildcard references
value
The value of the facet
category
The kind of identity constraint (key, unique, keyref)
referenced-key
The key referenced by the keyref
selector
The selector path in the identity constraint
fields
The field paths in the identity constraint
system
The notation's system identifier
public
The notation's public identifier
version
The schema's version
schema-location
The schema's location

Parameters:
$propname : The name of the component property to return.
$arg (optional): The component whose associated schema is to be returned.

Example:
declare namespace th="http://marklogic.com/xdmp/thesaurus";
xdmp:describe(
<th:thesaurus>
  <th:entry><th:term>dog</th:term>
     <th:synonym><th:term>canine</th:term></th:synonym>
  </th:entry>
</th:thesaurus>//th:entry/sc:schema()!sc:component-property("schema-location")
)
  =>
"thesaurus.xsd"

sc:element-decl(
[$arg as item()]
)  as   element-decl()?
Summary:

Returns the element declaration of item, as a schema component, if any. If the item has no element declaration, the empty sequence is returned. The context item is used if no argument is given.

  • If the item is a document node, the result is the element declaration of its root element.
  • If the item is an element node, the result is of its element declaration.
  • In other cases, the result is the empty sequence.

Parameters:
$arg (optional): The item whose element declaration is to be returned.

Example:
declare namespace th="http://marklogic.com/xdmp/thesaurus";
<decl>{
<th:thesaurus>
  <th:entry><th:term>dog</th:term>
     <th:synonym><th:term>canine</th:term></th:synonym>
  </th:entry>
</th:thesaurus>//th:entry/sc:element-decl()
}</decl>
  =>
<decl><xs:element name="entry" type="th:entry" xmlns:xs="http://www.w3.org/2001/XMLSchema">
    <xs:unique name="th:syn-term">
      <xs:selector>synonym</xs:selector>
      <xs:field xpath="term"/>
    </xs:unique>
  </xs:element></decl>

sc:facets(
[$arg as schema-component()]
)  as   element()*
Summary:

Returns the facets of the component, if any. Only simple types have facets. The context item is used if no argument is given.


Parameters:
$arg (optional): The item whose facets are to be returned.

Example:
for $f in sc:type-named(xs:QName('xs:NCName'))!sc:facets()
return data($f)
  =>
"collapse"
"[\i-[:]][\c-[:]]*"

sc:function-parameter-type(
$arg as function(*),
$param as xs:integer
)  as   schema-type()?
Summary:

Returns the declared parameter type of a specific parameter of the function item as a schema component.


Parameters:
$arg : The function item whose return type is to be returned.
$param : The number of the parameter, 1 for the first, 2 for the second, and so on. If the param is out of range, the empty sequence is returned.

Example:
  let $f := function-lookup(xs:QName("sc:function-parameter-type"),2)
  return (
    for $a in 1 to function-arity($f)
    return (concat("arg",$a,"=",sc:function-parameter-type($f,$a)))
  )
  =>
arg1=#xdmp:function
arg2=#xs:anyAtomicType

sc:function-return-type(
[$arg as function(*)]
)  as   schema-type()
Summary:

Returns the return type of a function item as a schema component. The context item is used if no argument is given.


Parameters:
$arg (optional): The function item whose return type is to be returned.

Example:
xdmp:describe(
  function-lookup(xs:QName("fn:normalize-unicode"),1) !
    sc:function-return-type(.)
)
  =>
#xs:string

sc:name(
[$arg as schema-component()]
)  as   xs:QName?
Summary:

Returns the name of the schema component, if any. The context item is used if no argument is given.


Parameters:
$arg (optional): The item whose name is to be returned.

Example:
declare namespace th="http://marklogic.com/xdmp/thesaurus";
xdmp:describe(
<th:thesaurus>
  <th:entry><th:term>dog</th:term>
     <th:synonym><th:term>canine</th:term></th:synonym>
  </th:entry>
</th:thesaurus>/th:entry/*[2]/sc:type()!sc:name())
  =>
xs:QName("th:synonym")

sc:particles(
[$arg as schema-component()]
)  as   schema-particle()*
Summary:

Returns the particles of the schema component, if any. The context item is used if no argument is given.


Parameters:
$arg (optional): The item whose particles are to be returned.

Example:
declare namespace th="http://marklogic.com/xdmp/thesaurus";
xdmp:describe(
<th:thesaurus>
  <th:entry><th:term>dog</th:term>
     <th:synonym><th:term>canine</th:term></th:synonym>
  </th:entry>
</th:thesaurus>/th:entry/&#42;[2]/sc:type()!sc:particles())
  =>
"(th:term&th:qualifiers?&th:scope-notes?&th:part-of-speech?)"

sc:schema(
[$arg as item()]
)  as   schema-root()?
Summary:

Returns the root schema of the item. The context item is used if no argument is given.

  • If the item is a document node, the result is the schema of its root element.
  • If the item is an element node, the result is the schema of its element declaration.
  • If the item is an attribute node, the result is the schema of its attribute declaration.
  • If the item is a schema component, the result is the containing schema.
  • If the item is an atomic value, the result is the schema containing the type of that atomic value.
  • In other cases, the result is the empty sequence.

Parameters:
$arg (optional): The item whose associated schema is to be returned.

Example:
declare namespace th="http://marklogic.com/xdmp/thesaurus";
xdmp:describe(
<th:thesaurus>
  <th:entry><th:term>dog</th:term>
     <th:synonym><th:term>canine</th:term></th:synonym>
  </th:entry>
</th:thesaurus>//th:entry/sc:schema()!sc:component-property("schema-location")
)
  =>
"thesaurus.xsd"

sc:schema-from-path(
$namespace as xs:string,
[$location as xs:string]
)  as   xs:string*
Summary:

Get a schema object as a value based on its namespace and schema location hint.


Parameters:
$namespace : The target namespace of the schema.
$location (optional): The location of the schema.


sc:simple-type(
[$arg as item()]
)  as   simple-type()?
Summary:

Returns the simple type of item, as a schema component, if any. If the item has a complex type rather than a simple type, the empty sequence is returned. The context item is used if no argument is given.

  • If the item is a document node, the result is the simple type of its root element.
  • If the item is an element node, the result is the simple type of its element declaration.
  • If the item is an attribute node, the result is the simple type of its attribute declaration.
  • If the item is a schema component, the result is the associated simple type schema component.
  • If the item is an atomic value, the result is the simple type of that atomic value.
  • In other cases, the result is the empty sequence.

Parameters:
$arg (optional): The item whose simple type is to be returned.

Example:
xdmp:describe(sc:simple-type(47))
  => "#xs:integer"

sc:type(
[$arg as item()]
)  as   schema-type()?
Summary:

Returns the type of item, as a schema component, if any. If the item has no type, the empty sequence is returned. The context item is used if no argument is given.

  • If the item is a document node, the result is the type of its root element.
  • If the item is an element node, the result is the type of its element declaration.
  • If the item is an attribute node, the result is the type of its attribute declaration.
  • If the item is a schema component, the result is the associated type schema component.
  • If the item is an atomic value, the result is the type of that atomic value.
  • In other cases, the result is the empty sequence.

Parameters:
$arg (optional): The item whose type is to be returned.

Example:
xdmp:describe(sc:type(47))
  => "#xs:integer"

sc:type-apply(
$type as schema-type(),
$arg as item()*
)  as   item()*
Summary:

Apply a type to an item to construct a typed instance of that type. If the type is a simple type this amounts to casting. If the type is a complex type this amounts to validating as that type.

Parameters:
$type : The type to apply.
$arg : The item to apply the type to.

Example:
sc:type-apply( sc:type-named(xs:QName('xs:integer')), "47" )
  => 47

sc:type-named(
[$arg as xs:QName]
)  as   schema-type()?
Summary:

Returns the type with the given name, if any, as a schema component. The context item is used if no argument is given.


Parameters:
$arg (optional): The type name.

Example:
sc:type-named('xs:integer')
  =>
#xs:integer