home contribute faq download

FunctX XSLT Functions

functx:sequence-type

The sequence type that represents a sequence of nodes or values

Google
Webxsltfunctions.com

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

NameTypeDescription
$items item()* the items whose sequence type you want to determine
return value xs:string

XSLT Function Declaration

See XQuery definition.
<xsl:function name="functx:sequence-type" as="xs:string"
              xmlns:functx="http://www.functx.com">
  <xsl:param name="items" as="item()*"/>

  <xsl:sequence select="
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 '')
   "/>

</xsl:function>

Examples

<xsl:variable name="in-xml" as="item()*">
<in-xml>
  <a att1="y">x</a>
  <b att1="x">x</b>
  <!-- comment -->
</in-xml>
</xsl:variable>
XSLT ExampleResultsExplanation
<functx:sequence-type(2)>unctx:sequence-type(2)
<xs:integer>s:integer
<functx:sequence-type(('abc','def'>)
<xs:string+>s:string+
<functx:sequence-type(('abc'>2))
<xs:anyAtomicType+>s:anyAtomicType+
<functx:sequence-type(>unctx:sequence-type( () )
<empty-sequence()>mpty-sequence()
<functx:sequence-type($in-xml>unctx:sequence-type($in-xml/*[1])
<element()>lement()
<functx:sequence-type($in-xml>unctx:sequence-type($in-xml/*)
<element()+>lement()+
<functx:sequence-type($in-xml>unctx:sequence-type($in-xml/*/@*)
<attribute()+>ttribute()+
<functx:sequence-type($in-xml>unctx:sequence-type($in-xml/*/text())
<text()+>ext()+
<functx:sequence-type($in-xml>unctx:sequence-type($in-xml/comment())
<comment()>omment()
<functx:sequence-type($in-xml>unctx:sequence-type($in-xml/node())
<node()+>ode()+
generic because there is a combination of node kinds (element and comment)
<functx:sequence-type(($in-xml/*,'2'>)
<item()+>tem()+
even more generic because there is a combination of nodes and an atomic value

Depends On

functx:node-kindThe XML node kind (element, attribute, text, etc.)
functx:atomic-typeThe built-in type of an atomic value

History

Published OnLast UpdatedContributor(s)
2007-08-082007-08-08Priscilla Walmsley, Datypic, pwalmsley@datypic.com, http://www.datypic.com
Datypic XSLT Services

Recommended Reading:

XQuery