Can DITA attribute values contain spaces?

Yes, DITA attribute values can contain spaces. Attribute values in DITA, like in many markup languages, are typically enclosed within double quotation marks (” “). This allows attribute values to include spaces, making it possible to represent text or data that contains whitespace characters.

The use of double quotation marks is essential for attribute values that include spaces because it clearly defines the beginning and end of the value, ensuring that spaces are treated as part of the value rather than as separators.

Attributes in DITA elements are assigned values using the following syntax:

<elementname attributename="attribute value with spaces">Content</elementname>

<elementname>: The name of the DITA element to which the attribute is applied.
attributename: The name of the attribute.
“attribute value with spaces”: The attribute value, enclosed within double quotation marks.

The use of double quotation marks ensures that spaces within the attribute value are considered part of the value. Without quotation marks, spaces might be interpreted as delimiters between separate attribute values.

Attribute values can contain various whitespace characters, including spaces and tabs. These whitespace characters are treated as part of the attribute value and are not used for separating values.

Example:

<topic>
    <title attributename="attribute value with spaces">
        This is the content of the title element.
    </title>
</topic>

In this example:

  • <title> is the DITA element.
  • attributename is the name of the attribute.
  • “attribute value with spaces” is the attribute value, enclosed within double quotation marks.
  • The content within <title> is unrelated to the attribute but is included to show the context of the element.