functx:all-whitespace

Whether a value is all whitespace or a zero-length string

Description

The functx:all-whitespace function tests whether a string (or node that is atomized) is all whitespace or empty. If $arg is the empty sequence, it returns true.

Parameters

Description

arg:string()

the string (or node) to test

Examples

The examples below use this input document:

<xsl:variable name="in-xml" as="item()*">
  <in-xml>
     <a>    </a>
     <b>x    </b>
     <c>  <x>x</x>    </c>
  </in-xml>

</xsl:variable>

XPath

Results

functx:all-whitespace(' ')

true

functx:all-whitespace(' x ')

false

functx:all-whitespace($in-xml/a)

true

functx:all-whitespace($in-xml/b)

false

functx:all-whitespace($in-xml/c)

false

functx:all-whitespace($in-xml/c/text()[1])

true

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-all-whitespace.

[e] example-functx-all-whitespace
    [e] vars
        [e] in-xml
            [e] select
                [v] copy-of(parse-xml('<in-xml><a>    </a><b>x    </b><c>  <x>x</x>    </c></in-xml>')/*)
    [e] start
        [e] match
            [v] /
        [e] body
            [e] write-pattern
                [v] examples
    [e] patterns
        [e] examples
            [v] E01: {{ functx:all-whitespace('   ') }}
            [v] E02: {{ functx:all-whitespace(' x  ') }}
            [v] E03: {{ functx:all-whitespace($in-xml/a) }}
            [v] E04: {{ functx:all-whitespace($in-xml/b) }}
            [v] E05: {{ functx:all-whitespace($in-xml/c) }}
            [v] E06: {{ functx:all-whitespace($in-xml/c/text()[1]) }}

See Also