Documentation Center

XML Parser rule example

Example: Select an element for translation based on an attribute value

The following parser rule specifies all elements that have the attribute value pair 'translate=yes', and ensures that these elements are presented for translation:

Rule identifier

Translate settings

The XPath identifier is:

//*[@translate="yes"]

This specifies that the rule applies to all elements that have the attribute translate with the value yes

Example: XPath and equivalent element specification

The SDL file type software uses XPath to specify elements, and you too can use XPath. However, you can also specify the element more simply in the Add/Edit Parser Rule dialog box.

XPath syntax

Equivalent element syntax

//text

In the Rule group box, Element box, enter the element name as: text

Example: XPath and equivalent for an element attribute pair

XPath syntax

Equivalent element syntax

//diagram/@address

  • In the Rule group box, Element box, enter the element name as: diagram
  • In the Rule group box, Attribute box, enter the element name as: address

Example: Use XPath to specify an attribute value pair

The XML example file, example-xml-file-letter.xml, includes elements that have an attribute translate, which can take the values yes and no. The intention is clear: all content within the scope of an attribute value translate="yes" should be translated.

//*[@translate="yes"]

We can break down this expression as follows:

//*Specifies all elements, at any depth.
[...]Square brackets delimit selection criteria. To specify elements by the values of an attribute (for example with =, > or <), surround the expression with square brackets.
@translateSpecifies the translate attribute.
="yes"Specifies elements for which the attribute has the value "yes".

Related topics