functx:has-empty-content
Whether an element has empty content
Description
The functx:has-empty-content function returns true if the element has no content at all (not even whitespace.) This is in contrast to the fn:empty function, which will return true for any element regardless of whether it has any content.
To test whether an element has any content besides whitespace, see the functx:all-whitespace function.
Parameters |
Description |
|---|---|
element:element() |
the XML element to test |
Examples
The examples below use this input document:
<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>
</in-xml>
</xsl:variable>
XPath |
Results |
|---|---|
functx:has-empty-content($in-xml/a) |
true |
functx:has-empty-content($in-xml/b) |
true |
functx:has-empty-content($in-xml/c) |
false |
functx:has-empty-content($in-xml/d) |
false |
functx:has-empty-content($in-xml/e) |
false |
functx:has-empty-content($in-xml/f) |
false |
functx:has-empty-content($in-xml/g) |
false |
In a generator
Copy the snippet below and paste it in Freemapper, under a language node inside the generators element. Each line of the pattern prints the result of one example; to see them, run mi generate <project> <language> example-functx-has-empty-content.
[e] example-functx-has-empty-content
[e] vars
[e] in-xml
[e] select
[v] copy-of(parse-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>')/*)
[e] start
[e] match
[v] /
[e] body
[e] write-pattern
[v] examples
[e] patterns
[e] examples
[v] E01: {{ functx:has-empty-content($in-xml/a) }}
[v] E02: {{ functx:has-empty-content($in-xml/b) }}
[v] E03: {{ functx:has-empty-content($in-xml/c) }}
[v] E04: {{ functx:has-empty-content($in-xml/d) }}
[v] E05: {{ functx:has-empty-content($in-xml/e) }}
[v] E06: {{ functx:has-empty-content($in-xml/f) }}
[v] E07: {{ functx:has-empty-content($in-xml/g) }}