Edit online

Configuring the Proposals for Attribute and Element Values

Oxygen XML Editor includes support for configuring the proposed values that appear in the Content Completion Assistant. To do so, a configuration file is used, along with the associated schema, to add or replace possible values for attributes or elements that are proposed in the Content Completion Assistant.

For an example of a specific use-case, suppose that you want the Content Completion Assistant to propose several possible values for the language code when you use an @xml:lang attribute.

Setting up the Content Completion Configuration File

To customize the configuration file for the Content Completion Assistant, follow these steps:
  1. Create a new resources folder (if it does not already exist) in the frameworks directory for the particular document type (for example, OXYGEN_INSTALL_DIR/frameworks/dita/resources).
  2. Open the Preferences dialog box (Options > Preferences) and go to Document Type Association. Select the particular document type, click the Edit button, and in the Classpath tab add a link to that resources folder (if it does not already exist).
  3. Create a new configuration file or edit an existing one.
    1. To easily create a new configuration file, you can use the Content Completion Configuration document template that is included in Oxygen XML Editor (File > New > Framework templates > Oxygen Extensions > Content Completion Configuration). The document template includes details about how each element and attribute is used in the configuration file.
    2. If a configuration file (cc_config.xml) already exists for the particular document type (in the resources folder), you can modify this existing file.
    3. If you extend a framework, you need to copy the content of the cc_config.xml file from the base framework and modify it. You also need to make sure that the file in your extension is listed in the Classpath tab before the one from the base framework. If you only want to make small changes or add extra rules in your content completion configuration file, you need to rename it to cc_config_ext.xml and it will be merged with the base cc_config.xml.
  4. Make the appropriate changes to your custom configuration file.
  5. Save the file in the resources folder for the particular document type, using the fixed name: cc_config.xml (for example, OXYGEN_INSTALL_DIR/frameworks/dita/resources/cc_config.xml).
  6. Restart the application and open an XML document. In the Content Completion Assistant you should see your customizations.
    Tip: In some cases, you can simply use the Refresh (F5) action to test your customizations, without having to restart the application.
    Attention: In the Classpath tab, if you have references to multiple resources folders, each with its own cc_config.xml file, the first reference listed in the Classpath tab takes precedence and the multiple configuration files are not combined.

Configuring Proposed Values

For the purposes of adding or replacing the values that are proposed, the configuration file (cc_config.xml) includes a series of match instructions that will match an element or attribute name. You also have the possibility of using an @editable attribute on the <match> element to specify the editable state of the attribute values, as reflected in the Attributes view and the In-place Attributes Editor. The possible values for the @editable attribute are:
  • true - The attribute values can be edited by choosing from a combo box or manually providing a value.
  • false - The attribute values cannot be edited.
  • onlyAllowedItems - The attribute values can be edited, but only by choosing from a list of proposed values, in a non-editable combo box.
A new value is specified inside one or more <item> elements, which are grouped inside an <items> element. The behavior of the <items> element is specified with the help of the @action attribute, which can have any of the following values:
  • append - Adds new values to appear in the proposals list (default value).
  • addIfEmpty - Adds new values to the proposals list only if no other values are contributed by the schema.
  • replace - Replaces the values contributed by the schema with new values to appear in the proposals list.

The values in the configuration file can be specified either directly or by calling an external XSLT file that will extract data from an external source.

Other Important Notes About the Configuration File

  • This configuration file only affects the content completion assistance, not validation.
  • To test the effects of your changes, you should restart the application.

Example: Specifying Values Directly

If you want to specify the values directly, the configuration file should look like this:

<!-- Replaces the values for an element with the local name "lg",
      from the given namespace -->
<match elementName="lg" elementNS="http://www.oxygenxml.com/ns/samples">
    <items action="replace">
        <item value="stanza"/>
        <item value="refrain"/>

<!-- Adds two values for an attribute with the local name "type",
      from any namespace -->
<match attributeName="type" editable="onlyAllowedItems">
        <item value="stanza"/>
        <item value="refrain"/>

Example: Calling an External XSLT Script

If you want to collect values from an external XSLT script, the configuration file should include something like this:

<xslt href="../xsl/get_values_from_db.xsl" useCache="false" action="replace"/>
In this example, the get_values_from_db.xsl is executed to extract values from a database.
Tip: You can use xsl:message as a debugging mechanism. These messages are presented in the results area at the bottom of the application whenever the Content Completion Assistant is invoked.
Note: A comprehensive XSLT sample is included in the Content Completion Configuration document template (in the Framework Templates > Oxygen Extensions section of the New document wizard).

Configuring Proposed Values in the Context Where the Content Completion was Invoked

Web Author Customization Note: This particular scenario is not supported for an Oxygen XML Web Author customization.

A more complex scenario is if you want to choose the possible values to propose, depending on the context of the element where the content completion was invoked.

Suppose that you want to propose certain possible values for one property (for example, color) and other values for another property (for example, shape). If the property represents a color, then the values should represent applicable colors, while if the property represents a shape, then the values should represent applicable shapes. See the following code snippets:

Your main document:
  <!-- The possible values for @value should be "red" and "blue" -->
  <property name="color" value=""/>
  <!-- The possible values for @value should be "square" and "rectangle" -->
  <property name="shape" value=""/>
The content completion configuration file:
<config xmlns="http://www.oxygenxml.com/ns/ccfilter/config">
    <match elementName="property" attributeName="value">
      <xslt href="get_values.xsl" useCache="false" action="replace"/>
The stylesheet that defines the possible values based on the context of the property on which the content completion was invoked:
  <xsl:param name="documentSystemID" as="xs:string"></xsl:param>
  <xsl:param name="contextElementXPathExpression" as="xs:string"></xsl:param>
  <xsl:template name="start">
    <xsl:apply-templates select="doc($documentSystemID)"/>
  <xsl:template match="/">
   <xsl:variable name="propertyElement" 
    select="saxon:eval(saxon:expression($contextElementXPathExpression, ./*))"/>
     <xsl:if test="$propertyElement/@name = 'color'">
       <item value='red'/>
       <item value='blue'/>  
     <xsl:if test="$propertyElement/@name = 'shape'">
       <item value='rectangle'/>
       <item value='square'/>  

The contextElementXPathExpression parameter will be bound to an XPath expression that identifies the element in the context where the content completion was invoked.