home contribute faq download

FunctX XSLT Functions

functx:has-element-only-content

Whether an element has element-only content

Google
Webxsltfunctions.com

Description

The functx:has-element-only-content function returns true if the element has only child elements, with no direct 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

XSLT Function Declaration

See XQuery definition.
<xsl:function name="functx:has-element-only-content" as="xs:boolean"
              xmlns:functx="http://www.functx.com">
  <xsl:param name="element" as="element()"/>

  <xsl:sequence select="
   not($element/text()[normalize-space(.) != '']) and $element/*
 "/>

</xsl:function>

Examples

<xsl:variable name="in-xml" as="item()*">
<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>
   <h><x>xml</x><y>xml</y></h>
   <i>  <x>xml</x>  <y>xml</y>  </i>
</in-xml>
</xsl:variable>
XPath ExampleResults
functx:has-element-only-content($in-xml/a)
false
functx:has-element-only-content($in-xml/b)
false
functx:has-element-only-content($in-xml/c)
false
functx:has-element-only-content($in-xml/d)
false
functx:has-element-only-content($in-xml/e)
true
functx:has-element-only-content($in-xml/f)
false
functx:has-element-only-content($in-xml/g)
true
functx:has-element-only-content($in-xml/h)
true
functx:has-element-only-content($in-xml/i)
true

See Also

functx:has-empty-contentWhether an element has empty content
functx:has-mixed-contentWhether an element has mixed 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 XSLT Services

Recommended Reading:

XQuery