Handling XML Comments

[SINCE: 2010-06-28]

Support

The Orbeon Forms pipeline engine supports XML comments. This means:
  • comments are preserved when parsing XML documents
  • transformations, e.g. XSLT, can consume and produce XML comments
  • comments are serialized to XML and HTML output
The URL Generator processor has an option to disable comments handling when parsing XML documents.

Producing comments from XSLT

You generate comments with the <xsl:comment> instruction:

<xsl:template match="/">
  <result>
    <xsl:comment> Cool comment.</xsl:comment>
  </result>
</xsl:template>

Simply putting an XML comment in an XSLT transformation does not cause comments to be produced in the output. The following won't work:

<xsl:template match="/">
  <result>
    <!-- Cool comment. -->
  </result>
</xsl:template>

You can for example output comments from an XSLT theme.

Accessing comments in XSLT

You access comments present in an input document with the comment() XPath function:

<xsl:template match="/">
    <comments>
        <xsl:for-each select="//comment()">
            <comment><xsl:value-of select="."/></comment>
        </xsl:for-each>
    </comments>
</xsl:template>

Comments in XForms

[SINCE: 2010-06-28]

Comments in XForms instances

Comments in XForms instances are preserved, whether instances are:
  • inline
  • loaded with <xforms:instance src="...">
  • loaded with <xforms:submission>
Comments in XForms instances are serialized through submissions that produce XML.

Example of comments within an inline instance:

<xforms:model id="model">
    <xforms:instance id="instance">
        <!-- This comment is ignored -->
        <labels xmlns="">
            <!-- This comment is preserved -->
            <label>Banana</label>
            <!-- This comment is preserved too -->
            <label>Strawberry</label>
        </labels>
        <!-- This comment is ignored -->
    </xforms:instance>
</xforms:model>

NOTE: Comments appearing before or after the document element (root element) of an inline instance, but within <xforms:instance>, are ignored.

Comments in instances can be accessed with the comment() XPath function:

<xforms:output value="string-join(//comment(), ' - ')"/>

Comments in other locations

XML comments are that are not contained within inline XForms instances are pruned by the XForms engine and are not present in the resulting HTML output.

Comments