In xslt, how to identify the xpath result has empty content

I put the xpath result into a variable x.
fn:empty($x) can only identify if the result sequence exists.
The $x could query into:

  1. a node with no value.
  2. a node with text value.
  3. a node with with sub-nodes.

How to identify case 1 so that I can put xsi:nil=“true” attribute to the output.