2.4. Extensibility

At times, it may be useful to extend the set of information available in an XLIFF document by inserting constructs defined in various other XML vocabularies. There are several ways to do this in XLIFF. All of them use the namespace mechanism [XML Names]. You can add non-XLIFF elements, as well as attributes and attribute values.

Although XLIFF offer this extensibility mechanism, in order avoid a nimiety of information and increase interoperability between tools, it is strongly recommended to use XLIFF capabilities whenever possible, rather than to create non-standard user-defined elements or attributes.

2.4.1. Adding Elements

XLIFF provides several extension points in the following elements: <header>, <group>, <trans-unit>, <alt-trans>, and  <bin-unit>. Within each of these elements, the extension point is located just before the optional <note> elements; that is also just after where the optional <prop-group> elements (now deprecated) would be.

Several non-XLIFF element can be used at each extension point. The content of each element can be any valid XML content (empty content, PCDATA, mixed content, and so forth).

For example, the following XLIFF code shows how to add user-defined element (in bold) within an XLIFF document:

<xliff version='1.1'
 xmlns='urn:oasis:names:tc:xliff:document:1.1'
 xmlns:sup='http://www.ChaucerState.ac.pg/Frm/XLFSup-v1'>
 <file original='passus-1.doc' source-language='enm' datatype='plaintext'>
  <group>
   <sup:SourceInfo>
    <sup:Book>Piers Plowman, Passus 1</sup:Book>
    <sup:Author>William Langland</sup:Author>
   </sup:SourceInfo>
   <sup:WorkInfo Task='transcription' Context='Middle-English:1360'/>
   <trans-unit id='1'>
    <source xml:lang='enm'>What this mountaigne bymeneth</source>
    <target xml:lang='en'>What this mountain means</target>
    <sup:Reference Type='strophe'>1-a</sup:Reference>
   </trans-unit>
   <trans-unit id='2'>
    <source xml:lang='enm'>and the merke dale</source>
    <target xml:lang='en'>and the dark dale</target>
    <sup:Reference Type='strophe'>1-b</sup:Reference>
   </trans-unit>
   <trans-unit id='3'>
    <source xml:lang='enm'>And the feld ful of folk</source>
    <target xml:lang='en'>And the field full of folk</target>
    <sup:Reference Type='strophe'>2-a</sup:Reference>
   </trans-unit>
   <trans-unit id='4'>
    <source xml:lang='enm'>I shal yow faire shewe.</source>
    <target xml:lang='en'>I fairly will show.</target>
    <sup:Reference Type='strophe'>2-b</sup:Reference>
   </trans-unit>
  </group>
 </file>
</xliff>

The non-XLIFF elements used in the example above would be defined as the following:

<xsd:schema targetNamespace="XLFSup-v1"
 xmlns:xsd="http://www.w3.org/2001/XMLSchema"
 xmlns:sup="http://www.ChaucerState.ac.pg/Frm/XLFSup-v1"
 elementFormDefault="qualified" attributeFormDefault="unqualified">
 <xsd:element name="SourceInfo">
  <xsd:complexType>
   <xsd:sequence maxOccurs="unbounded">
    <xsd:element name="Book" type="xsd:string"/>
    <xsd:element name="Author" type="xsd:string"/>
   </xsd:sequence>
  </xsd:complexType>
 </xsd:element>
 <xsd:element name="WorkInfo">
  <xsd:complexType>
   <xsd:attribute name="Task" type="xsd:string"/>
   <xsd:attribute name="Context" type="xsd:string"/>
  </xsd:complexType>
 </xsd:element>
 <xsd:element name="Reference">
  <xsd:complexType>
   <xsd:simpleContent>
    <xsd:extension base="xsd:string">
     <xsd:attribute name="Type" type="xsd:string"/>
    </xsd:extension>
   </xsd:simpleContent>
  </xsd:complexType>
 </xsd:element>
</xsd:schema>

It is not possible to add non-XLIFF elements in neither the <source> and <target> elements. However, the <mrk> element can be used to markup sections of the text with user-defined values assigned to the mtype attribute. You can also add non-XLIFF attributes to most of the inline elements used in <source> and <target>.

2.4.2. Adding Attributes

Attributes of a namespace different than XLIFF can be included in several XLIFF elements.

The following elements allow non-XLIFF attributes: <file>, <group>, <trans-unit>, <source>, <target>, <bin-unit>, <bin-source>, <bin-target>, <alt-trans>, <mrk>, <g>, <x/>, <bx/>, <ex/>, <bpt>, <ept>, <ph>, and <it>.

For instance, the following XLIFF code illustrates how to use attributes from the XHTML vocabulary (in bold) in the the <group> and <trans-unit> XLIFF elements. The example show how to carry formatting information about the an extracted table:

<xliff version='1.1'
 xmlns='urn:oasis:names:tc:xliff:document:1.1'
 xmlns:htm='http://www.w3.org/TR/REC-html40'>
 <file original='table.htm' source-language='en' datatype='html'>
  <group restype='table' htm:border='1' htm:cellpadding='5'
   htm:cellspacing='0' htm:width='100%'>
   <group restype='row'>
    <trans-unit id='1' htm:valign='top' htm:width='30%'>
     <source>Text of row 1 column 1</source>
    </trans-unit>
    <trans-unit id='1' htm:valign='top' htm:width='30%'>
     <source>Text of row 1 column 2</source>
    </trans-unit>
   </group>
   <group restype='row'>
    <trans-unit id='1' htm:valign='top' htm:width='30%'>
     <source>Text of row 2 column 1</source>
    </trans-unit>
    <trans-unit id='1' htm:valign='top' htm:width='30%'>
     <source>Text of row 2 column 2</source>
    </trans-unit>
   </group>
  </group>
 </file>
</xliff>

In each of the XLIFF elements allowing non-XLIFF attributes: there is no specific location where to insert the non-XLIFF attributes, and there is no limit to the number of non-XLIFF attributes that can be used.

2.4.3. Adding Attribute Values

[YS note: I'm not very comfortable with this solution for the following reasons:
-- It would be nice to be able to make a distinction between standard and extended values with namespace prefixes (e.g. standard would be without, extended would have one).
-- Using several sets of user-defined extended values will require to make union of extended types, not very elegant.
Something tells me that there is a better way to implement those extended values. But I don't know better. If anyone has a better understanding of XSD to do this more elegantly...]

Many attributes in XLIFF offer a list of enumerated values. Some applications may found necessary to add user-defined values to these lists. XLIFF allows for such extension.

The attributes where the list of values can be extended are the following: context-type, count-type, ctype, datatype, mtype, restype, size-unit, state, unit, and priority.

The lists of values for XLIFF attributes are defined in a specific schema. Each list has a set of pre-defined standard values declared as a type in that schema. A second schema is reserved for declaring extended values. This file contains a type for each set of extended values. The type used in the definition of the value for a given element is the union of both the standard type and the extended type.

For example, the standard values for the attribute context-type that is used in the <context> element are defined as follow:

<xsd:simpleType name="context-typeValueListStd">
 <xsd:restriction base="xsd:NMTOKEN">
  <xsd:enumeration value="database"/>
  <xsd:enumeration value="element"/>
  <xsd:enumeration value="elementtitle">
  <xsd:enumeration value="recordtitle">
 </xsd:restriction>
</xsd:simpleType>

Extended values can be defined in the type context-typeValueListExt, reserved for this:

<xsd:simpleType name="context-typeValueListExt">
 <xsd:restriction base="xsd:NMTOKEN">
  <!-- Add your values here -->
  <xsd:enumeration value="user-defined-value1"/>
 </xsd:restriction>
</xsd:simpleType>

The type assigned to the context-type attribute is the union of both standard and extended types:

<xsd:simpleType name="context-typeValueList">
 <xsd:union memberTypes="context-typeValueListStd context-typeValueListExt"/>
</xsd:simpleType>
<xsd:complexType name="ElemType_context">
 <xsd:simpleContent>
  <xsd:extension base="xsd:string">
   <xsd:attribute name="context-type" type="xlfv:context-typeValueList" use="required"/>
   ...
  </xsd:simpleContent>
</xsd:complexType>

To define your own values, and be able to validate the documents that use them, you need to enumerate the values in the type declaration of the relevant extended value list. For instance, if you defined the following values for the extended value list for context-type, you can use them in an XLIFF document.

<xsd:simpleType name="context-typeValueListExt">
 <xsd:restriction base="xsd:NMTOKEN">
  <!-- Add your values here -->
  <xsd:enumeration value="for-translators"/>
  <xsd:enumeration value="for-engineers"/>
  <xsd:enumeration value="for-authors"/>
  <xsd:enumeration value="for-editors"/>
 </xsd:restriction>
</xsd:simpleType>
...
<group>
 <context-group name='EngineersData'>
  <context context-type='for-engineers'>Data...</context>
...

2.4.4. Validating Documents with Extensions

In order to validate an XLIFF document that contains non-XLIFF parts, you can use the schema validation mechanism: In addition to the namespace declarations, add the schemaLocation attribute of the XMLSchema-instance namespace to define what schemas to use to validate the document (XLIFF and the non-XLIFF namespaces).

<xliff version='1.1'
 xmlns='urn:oasis:names:tc:xliff:document:1.1'
 xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
 xsi:schemaLocation='
  urn:oasis:names:tc:xliff:document:1.1 xliff-1-1.xsd
  urn:oasis:names:tc:xliff-values:document:1.1 xliff-values-1-1.xsd
  urn:oasis:names:tc:xliff-values-extensions:document:1.1 xliff-values-1-1-extensions.xsd
  http://www.ChaucerState.ac.pg/Frm/XLFSup-v1 XLFSup-v1.xsd'
>
...
</xliff>

See http://www.w3.org/XML/Schema for more information on XML Schema and validation.