content is

operator

Return type:
Switch
Returns:
Return true if the content is of the specified type, and false otherwise. Replacing is with isnt reverses the result.
Syntax
content (of element-expression)? (is | isnt) (content-type | content-type-list)
    


Purpose

The content is test tests an element's declared content type or content model type. It can also be used to determine if an element has a conref attribute, in which case the element is effectively EMPTY, no matter what its declared type is.

The content type can be:

  • any, indicating an element with a content model of ANY,
  • empty, indicating an element with a declared content of EMPTY or an XML empty element tag ("<foo/>"),
  • declared-empty, indicating an element with a declared content of EMPTY,
  • empty-tag, indicating an element with an XML empty element tag ("<foo/>"),
  • cdata, indicating an element with a declared content of CDATA,
  • rcdata, indicating an element with a declared content of RCDATA,
  • element, indicating an element with a content model that allows other elements but does not allow #PCDATA,
  • conref, indicating an element for which a CONREF attribute has been specified, and
  • mixed, indicating an element declared with a content model that allows #PCDATA or a content model of ANY. (The content model ANY allows #PCDATA.) Elements declared with a content model of ANY satisfy the tests for both MIXED content models and the ANY content model. So if ANY and MIXED are to be distinguished, any should be tested before mixed. In essence, any overrides mixed.

A content-type-list is a list of content types separated by or or |.

If element-expression is specified, the test applies to the qualified element. Otherwise, the current element is tested.

The following element rule illustrates how content is tests can be used to provide an analysis of every element in a document:

  element #implied
     output "%n<%q>: "
     do when content is element
       output "element"
  
     else when content is any
       output "any"
  
     else when content is mixed
       output "mixed"
  
     else when content is cdata
       output  "cdata"
  
     else when content is rcdata
       output "rcdata"
  
     else when content is empty
       output "empty"
     done
  
     output " (conref)" when content is conref
     output "%n"
  
     output "%c"

Related Syntax