Sequence Types and Schemas
Chapter 11 showed how sequence types are used to match sequences in various expressions, including function calls. When schemas have been imported into a query, additional tests are available for sequence types, including testing for name and type. Their syntax is shown in Figure 13-4. These tests can be used not just in sequence types but also as kind tests in path expressions.
Figure 13-4. Element and attribute tests (for sequence types and kind tests)
Chapter 11 introduced the element( )
and attribute( )
tests. For example, you can use the test element(prod:product)
to test for elements whose name is prod:product
.
These tests can also be used with user-defined types. For example, the sequence type:
element(prod:product, prod:ProductType)
matches an element whose name is prod:product
and that has the type prod:ProductType
, or any type derived by restriction or extension from prod:ProductType
. Yet another syntax is:
element(*, prod:ProductType)
which matches any element that has the type prod:productType
(or a derived type), regardless of name. Note that the element must already have been validated and annotated with the type prod:ProductType
. It is not enough that it would be a valid instance of that type if it were validated.
You can also match an element or attribute based on its name using the schema-element( )
and schema-attribute( )
tests. For ...
Get XQuery now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.