Testing for empty WYSIWYG field

Testing to see if a WYSIWYG field can be tricky since the field could either contain plain text or HTML elements.

One solution is to test if the value of an XML Element is not empty, or if the Element contains children (ie the HTML elements).

Using Velocity

## Record the WYSIWYG field
#set ( $wysiwygField = $_XPathTool.selectSingleNode($contentRoot, "//wysiwyg-field")) 

## Test to see if the Element's value is not empty, or if the Element has children
#if ($wysiwygField.value != "" or $wysiwygField.getChildren().size() > 0)
    $_SerializerTool.serialize($wysiwygField, true))

Using XSLT

<xsl:if test="wysiwygField/node()">
    <!-- use xsl:copy-of here to make sure that all child nodes and attributes are copied as well -->
    <xsl:copy-of select="wysiwygField/node()"/>