Description
The functx:sequence-type function checks the types and/or node kinds of one or more items ($items) and returns a sequence type that matches $items. This is useful for debugging and testing the composition of a sequence.
Arguments and Return Type| Name | Type | Description |
$items |
item()* |
the items whose sequence type you want to determine |
| return value |
xs:string |
XQuery Function Declaration| See XSLT definition. | | XQuery Syntax for January 2007 (1.0): |
|---|
declare namespace functx = "http://www.functx.com";
declare function functx:sequence-type
( $items as item()* ) as xs:string {
concat(
if (empty($items))
then 'empty-sequence()'
else if (every $val in $items
satisfies $val instance of xs:anyAtomicType)
then if (count(distinct-values(functx:atomic-type($items)))
> 1)
then 'xs:anyAtomicType'
else functx:atomic-type($items[1])
else if (some $val in $items
satisfies $val instance of xs:anyAtomicType)
then 'item()'
else if (count(distinct-values(functx:node-kind($items))) > 1)
then 'node()'
else concat(functx:node-kind($items[1]),'()')
,
if (count($items) > 1)
then '+' else '')
} ; | | XQuery Syntax for July 2004 - November 2005 (CR): |
|---|
declare namespace functx = "http://www.functx.com";
declare function functx:sequence-type
( $items as item()* ) as xs:string {
concat(
if (empty($items))
then 'empty-sequence()'
else if (every $val in $items
satisfies $val instance of xdt:anyAtomicType)
then if (count(distinct-values(functx:atomic-type($items)))
> 1)
then 'xdt:anyAtomicType'
else functx:atomic-type($items[1])
else if (some $val in $items
satisfies $val instance of xdt:anyAtomicType)
then 'item()'
else if (count(distinct-values(functx:node-kind($items))) > 1)
then 'node()'
else concat(functx:node-kind($items[1]),'()')
,
if (count($items) > 1)
then '+' else '')
} ; | | XQuery Syntax for May 2003: |
|---|
declare namespace functx = "http://www.functx.com"
define function sequence-type
( $items as item()* ) as xs:string {
fn:concat(
if (fn:empty($items))
then 'empty-sequence()'
else if (every $val in $items
satisfies $val instance of xdt:anyAtomicType)
then if (fn:count(fn:distinct-values(functx:atomic-type($items)))
> 1)
then 'xdt:anyAtomicType'
else functx:atomic-type($items[1])
else if (some $val in $items
satisfies $val instance of xdt:anyAtomicType)
then 'item()'
else if (fn:count(fn:distinct-values(functx:node-kind($items))) > 1)
then 'node()'
else fn:concat(functx:node-kind($items[1]),'()')
,
if (fn:count($items) > 1)
then '+' else '')
} |
Exampleslet $in-xml := | <in-xml>
<a att1="y">x</a>
<b att1="x">x</b>
<!-- comment -->
</in-xml> | return |
| XQuery Example | Results | Explanation |
|---|
functx:sequence-type(2)
|
xs:integer
|
functx:sequence-type(('abc','def'))
|
xs:string+
|
functx:sequence-type(('abc',2))
|
xs:anyAtomicType+
|
functx:sequence-type( () )
|
empty-sequence()
|
functx:sequence-type($in-xml/*[1])
|
element()
|
functx:sequence-type($in-xml/*)
|
element()+
|
functx:sequence-type($in-xml/*/@*)
|
attribute()+
|
functx:sequence-type($in-xml/*/text())
|
text()+
|
functx:sequence-type($in-xml/comment())
|
comment()
|
functx:sequence-type($in-xml/node())
|
node()+
|
generic because there is a combination of node kinds (element and comment) |
functx:sequence-type(($in-xml/*,'2'))
|
item()+
|
even more generic because there is a combination of nodes and an atomic value |
Depends OnHistory |
|