Redenaji
Redenaji

Reputation: 13

What does not(*|@*) mean in XSLT / XPath?

Could anyone explain me what does this line of code actually do:

<xsl:when test="not(*|@*)">

I get it that expression inside of brackets needs to be false for it to trigger next lines of code, I am just not sure how to interpret it.

Upvotes: 1

Views: 672

Answers (1)

kjhughes
kjhughes

Reputation: 111541

The test will pass when the current node has no child elements or attributes of any name:

  • * selects child elements of the current node, regardless of name;
  • @* selects attributes of the current node, regardless of name;
  • | is the union operator and combines the node sets (or sequences) of its operands;
  • not() will convert its argument to a boolean value before inverting it. In the case of node sets (or sequences), emptiness will convert to false, inverting to true. Thus, iff no child elements and no attributes exist, their set-union via | will be empty, and not() will return true, thereby implementing a test for no child elements and no attributes.

Credit: Thanks to @DimitreNovatchev for several helpful improvements to this answer.

Upvotes: 3

Related Questions