home contribute faq download

FunctX XQuery Functions

functx:has-mixed-content

Whether an element has mixed content

Google
Webxqueryfunctions.com

Description

The functx:has-mixed-content function returns true if the element has mixed content, i.e. both child elements and textual (character data) content other than whitespace.

Technically, when a schema is not in use, the spaces and line breaks used to pretty-print XML documents do count as text nodes. However, for convenience, this function ignores them.

Arguments and Return Type

NameTypeDescription
$element element() the XML element to test
return value xs:boolean

XQuery Function Declaration

See XSLT definition.
declare namespace functx = "http://www.functx.com";
declare function functx:has-mixed-content
  ( $element as element() )  as xs:boolean {

   $element/text()[normalize-space(.) != ''] and $element/*
 } ;

Examples

let $in-xml :=
<in-xml>
   <a></a>
   <b/>
   <c>   </c>
   <d>xml</d>
   <e><x>xml</x></e>
   <f>mixed <x>xml</x></f>
   <g> <x>xml</x>  </g>
</in-xml>
return
XQuery ExampleResults
functx:has-mixed-content($in-xml/a)
false
functx:has-mixed-content($in-xml/b)
false
functx:has-mixed-content($in-xml/c)
false
functx:has-mixed-content($in-xml/d)
false
functx:has-mixed-content($in-xml/e)
false
functx:has-mixed-content($in-xml/f)
true
functx:has-mixed-content($in-xml/g)
false

See Also

functx:has-empty-contentWhether an element has empty content
functx:has-element-only-contentWhether an element has element-only content
functx:has-simple-contentWhether an element has simple content
functx:all-whitespaceWhether a value is all whitespace or a zero-length string

History

Published OnLast UpdatedContributor(s)
2007-04-302007-04-30Priscilla Walmsley, Datypic, pwalmsley@datypic.com, http://www.datypic.com
Datypic XQuery Services

Recommended Reading:

XQuery