0% found this document useful (0 votes)
28 views7 pages

XPath (TMS) - Phrase

This document provides examples of XPath expressions that can be used to selectively import elements and attributes from XML documents for machine translation. It gives 20 examples of XPath expressions with descriptions of what each expression imports. It also discusses using XPath to import context notes from source segments into translated segments.

Uploaded by

Zhihao Wang
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
28 views7 pages

XPath (TMS) - Phrase

This document provides examples of XPath expressions that can be used to selectively import elements and attributes from XML documents for machine translation. It gives 20 examples of XPath expressions with descriptions of what each expression imports. It also discusses using XPath to import context notes from source segments into translated segments.

Uploaded by

Zhihao Wang
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

Import Utilities

 Enter keywords

Phrase TMS Phrase Strings Phrase Orchestrator Global Release notes Release Notes Archive

Phrase TMS / Import Utilities

XPath (TMS)
Article content is machine translated from English to other languages by Phrase Translate.

XPath stands for XML Path Language. It can be used to navigate through elements and attributes in
an XML document. If new to XPATH, please see the XPath Tutorial  first and study the official XPATH
documentation .

A subset of XPath 1.0 is supported with the following limitations:

Axis in step

Supported

ancestor, ancestor-or-self, attribute, child, descendant, descendant-or-self

Not supported

following, preceding, following-sibling, preceding-sibling, namespace

Predicate

Supported

conditions on current node or ancestor nodes and its properties (attributes, namespaces)

Not supported (for example)


position number, axis child::, descendant, descendant-or-self, following::, preceding::,
following-sibling::, preceding-sibling::, function last()

Basic rules

Use / and // in paths

Use single quotes ' ' in names

Use a pipe | for joining the requests

Names are case-sensitive: <Body> is different from <body>

Examples

XPath Example 1  and XPath example 2  (with namespace) are example files for the following:

1. Import all elements and all attributes

//* | //@*

2. Import all elements and the value of attribute1

(<elem1 attribute1="translate" attribute2="Do not translate"/>)

//* | //@attribute1

3. Import all descendants of Child elements

//Child//*

4. Import an element lis and its descendants only if the attribute translate='true'

(<lis translate="true">translate this</lis><lis translate="false">do not translate this</lis>)

//lis[@translate='true']/descendant-or-self::*

5. Import all elements and descendants if the element's attribute is translate='true'

//*[@translate='true']/descendant-or-self::*

6. Import value of the attribute Text in element Data

<Data Text="Text for translation">

//data/@text

7. Import the <mT:translation> element and its descendants, except element <mT:ignore>
//mT:translation/descendant-or-self::*[not(ancestor-or-self::mT:ignore)]

8. Exclude all elements with the attribute translate='false'

//*[not(@translate='false')]

9. Exclude elements 'lis' with the attribute translate='false'

(<lis translate="false">Do not translate)

//*[not(self::lis[@translate='false'])]

10. Exclude elements 'lis' with the attribute translate='false' and their descentants

(<lis translate="false"><p>Do not translate)

//*[not(ancestor-or-self::lis[@translate='false'])]

11. Exclude all elements containing 'link'

(<menu1link><tmenu41link>)

//*[not(contains(name(),'link'))]

12. Exclude all elements if they or their ancestor have an attribute 'lis' containing 'link'

(<ele lis=menu1link>, <mon lis=tmenu41link>)

//*[not(ancestor-or-self::node()[contains(@lis, 'link')])]

13. Import elements PT if their parent LANG has the attribute 'updated' with year 2015

(<LANG updated="20150213T121526"><PT>'

//LANG[contains(@updated,'2015')]/PT

14. Import elements 'Description' and 'Name' only if they are not descendants of elements
'Definitions' or 'Types'

://*[not(ancestor-or-self::*[(name()='Definitions') or (name()='Types')])]/*

[(name()='Description') or (name()='Name')]

15. XML with namespace

<root xmlns:xhtml="http://www.w3.org/1999/xhtml"><Child><Text>translate this</Text></Child>

import all elements in <Child> :

//*[local-name()='Child']//*

import only elements <Text> in <Child> :


//*[local-name()='Child']/*[local-name()='Text']

import all elements under element <CONTRACT> , if attribute <CATEGORY> in <CONTRACT> has
the value <ORIGINAL>

://*[local-name()='CONTRACT' and @CATEGORY='ORIGINAL']//*

16. XML with namespace and attributes <root> xmlns:xhtml="http://www.w3.org/1999/xhtml"<Child

translate='1'>translate this</Child>

import element <Child> if the attribute translate is 1: //*[local-name()="Child"][@*[local-


name()='translate']='1']

import all elements with the attribute translate=true: //*[@*[local-


name()='translate']='true']

17. XML with namespace. Import the element target from element tu , but not when the attribute id
contains 'img' or 'extra':

a. File example:

<tu id="pages|content|extra"><ori xml:lang="en">Course one</ori><target xml:lang="lang">Course

one</target></tu>

b. XPATH example:

//*[local-name()='tu' and not(contains(@id,'img') or contains(@id,'extra'))]/*[local-

name()='target']

18. Import all elements except <comment> and <lis> unless <lis translate="true"> and their
descendants:

//*[count(ancestor-or-self::node()[(name()='lis' and (not(@translate='true')) ) or

name()='comment'])=0]

19. Import all elements except <comment> and except elements with attribute <... attribute2="Do
not translate"> and their descendants:

//*[count(ancestor-or-self::node()[(@attribute2='Do not translate') or name()='comment'])=0]

20. Import values of attributes varName and glossName but only if their ancestors have attribute
attribute1='translate' or attribute1='edit' :

//*[(self::node()[@attribute1='translate' or @attribute1='edit'])]//@*[local-name()='varName' or

local-name()='glossName']
21. Import all elements and attributes except elements with the attribute Name= Back , Menu , or
Time :

//*[not(ancestor-or-self::node()[@Name='Back' or @Name='Menu' or @Name='Time'])] | //@*

[not(ancestor-or-self::node()[@Name='Back' or @Name='Menu' or @Name='Time'])]

In this case it may be better to import all and lock the attributes not required for import. Once
segments are Locked, copy source to target in the editor in order to have the original transferred
to translation.

a. Lock all elements with the attribute Name with values: Back , Menu , or Time and their
descendants:

//*[@Name='Back' or @Name='Menu' or @Name='Time']/descendant-or-self::*

b. Lock all attributes of Name with values: Back , Menu , or Time and their descendants

//*[@Name='Back' or @Name='Menu' or @Name='Time']//@*

Some external examples .

Context note

Context notes can be imported into translated segments.

There are three examples in this sample:

<?xml version-"1.0" encoding="utf-8"?>

<root>

<element context1="Note in attribute of parentElement 1 - select ../@context1">

<field context2="Note in attribute 1 - select @context2" >for translation1</field>

<context3>Note in element 1 - select ../context3</context3>

</element>

<element context1="Note in attribute of parentElement 2">

<field context2="Note in attribute 2">for translation2</field>

<context3>Note in element 2</context3>

</element>

</root>

Attribute in parent element (context 1): ../@context1


Attribute in self element (context2): @context2

Sibling element (context 3): ../context3
If importing Elements&Attributes: //* the content of the context note will be imported to source
segments as well. Exclude the context note elements/attributes from general import in
Elements&Attributes.

 xpath_example2.xml
(2 KB)

 xpath_example1.xml
(2 KB)

Was this article helpful?

 Yes  No

Recently viewed articles

.XML - Extensible Markup Language (TMS)

In this article

Basic rules
Examples
Context note

  

RESOURCES

Free Trial
Download Editor
Blog
Release Notes
Feature requests
Webinars

You might also like