유틸리티 가져오기

XPath (TMS)

컨텐츠는 영어 텍스트를 Phrase Language AI를 이용해 기계 번역한 것입니다.

XPath는 XML Path Language의 약자입니다. XML 문서 내의 요소와 속성을 탐색하는 데 사용할 수 있습니다. XPATH를 처음 접하는 경우, 먼저 XPath 튜토리얼을 확인하고 공식 XPATH 문서를 공부하십시오.

AI 챗봇은 Xpath를 생성하고 검증하는 데 매우 효과적일 수 있습니다.

XPath 1.0의 하위 집합이 다음 제한 사항과 함께 지원됩니다:

  • 단계 내 축(Axis)

    • 지원

      ancestor, ancestor-or-self, attribute, 하위 요소, descendant, descendant-or-self

    • 지원 불가

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

  • 조건식(Predicate)

    • 지원

      현재 노드나 상위 노드 및 해당 속성(속성, 네임스페이스)에 대한 조건

    • 지원 불가 (예시)

      위치 번호, 축 child::, descendant, descendant-or-self, following::, preceding::, following-sibling::, preceding-sibling::, 함수 last()

기본 규칙

  • 경로에 /// 사용

  • 이름에 작은따옴표 ' ' 사용

  • 요청을 결합하려면 파이프 | 사용

  • 이름은 대소문자를 구분합니다: <Body><body>와 다릅니다

**Examples**

XPath 예 1XPath 예 2 (네임스페이스 포함)는 다음을 위한 예시 파일입니다:

  1. 모든 요소와 모든 속성 가져오기

    //* | //@*

  2. 모든 요소와 attribute1의 값 가져오기

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

    //* | //@attribute1

  3. 하위 요소의 모든 자손 가져오기

    //Child//*

  4. translate='true' 속성이 있는 경우에만 lis 요소와 그 자손 가져오기 

    (<lis translate=\"true\">이것을 번역하십시오</lis><lis translate=\"false\">이것을 번역하지 마십시오</lis>)

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

  5. 요소의 속성이 translate='true'인 경우 모든 요소와 자손 가져오기

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

  6. Data 요소의 Text 속성 값 가져오기

    <Data Text=\"번역할 텍스트\">

    //data/@text

  7. <mT:translation> 요소와 그 하위 요소를 가져오되, <mT:ignore> 요소는 제외

    //mT:translation/descendant-or-self::*[not(ancestor-or-self::mT:ignore)]

  8. translate='false' 속성을 가진 모든 요소 제외

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

  9. translate='false' 속성을 가진 'lis' 요소 제외

    (<lis translate=\"false\">번역하지 마십시오)

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

  10. translate='false' 속성을 가진 'lis' 요소와 그 하위 요소 제외

    (<lis translate=\"false\"><p>번역하지 마십시오)

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

  11. 'link'를 포함하는 모든 요소 제외

    (<menu1link><tmenu41link>)

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

  12. 요소 또는 그 상위 요소가 'link'를 포함하는 'lis' 속성을 가진 경우 모든 요소 제외

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

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

  13. 상위 요소 LANG의 'updated' 속성 연도가 2015년인 경우 PT 요소를 가져오기 합니다.

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

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

  14. 'Definitions' 또는 'Types' 요소의 하위 요소가 아닌 경우에만 'Description' 및 'Name' 요소를 가져오기 합니다.

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

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

  15. 네임스페이스가 있는 XML

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

    • <Child>의 모든 요소를 가져오기 합니다:

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

    • <Child> 내의 <Text> 요소만 가져오기 합니다:

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

    • <CONTRACT><CATEGORY> 속성 값이 <ORIGINAL>인 경우, <CONTRACT> 요소 아래의 모든 요소를 가져오기 합니다.

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

  16. 네임스페이스와 속성이 있는 XML <root> xmlns:xhtml=\"http://www.w3.org/1999/xhtml\"<Child translate='1'>이 내용을 번역하세요</Child>

    • translate 속성이 1인 경우 하위 요소 <Child>를 가져오기 합니다: //*[local-name()=\"Child\"][@*[local-name()='translate']='1']

    • translate=true 속성이 있는 모든 요소를 가져오기 합니다: //*[@*[local-name()='translate']='true']

  17. 네임스페이스가 있는 XML. 요소 tu에서 대상 요소를 가져오기 하되, ID 속성에 'img' 또는 'extra'가 포함된 경우는 제외합니다:

    1. 파일 예시:

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

    2. XPATH 예시:

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

  18. <lis translate=\"true\"> 및 그 하위 요소를 제외하고 <comment><lis>를 제외한 모든 요소를 가져오기 합니다.

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

  19. <주석><1>과 <... attribute2=\"Do not translate\"><2> 속성이 있는 요소를 제외한 모든 요소와 그 하위 요소를 가져오기합니다:

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

  20. varName<1> 및 glossName<2> 속성 값을 가져오기하되, 상위 요소에 attribute1='translate'<3> 또는 attribute1='edit'<4> 속성이 있는 경우에만 가져오기합니다:

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

  21. Name= Back, Menu<2> 또는 Time<3> 속성이 있는 요소를 제외한 모든 요소와 속성을 가져오기합니다:

    //*[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'])]

    이 경우 모두 가져오기하고 가져오기에 필요하지 않은 속성을 잠그는 것이 더 나을 수 있습니다. 세그먼트가 잠기면 편집자에서 소스를 대상으로 복사하여 원본이 번역으로 전송되도록 합니다.

    1. Name<1> 속성 값이 Back, Menu 또는 Time인 모든 요소와 그 하위 요소를 잠급니다:

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

    2. Name<1> 속성 값이 Back, Menu 또는 Time인 모든 속성과 그 하위 요소를 잠급니다

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

일부 외부 예시<1>.

컨텍스트 메모

컨텍스트 메모는 번역된 세그먼트로 가져오기할 수 있습니다.

이 샘플에는 세 가지 예시가 있습니다:

<?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="상위 요소 2의 속성에 있는 컨텍스트 메모">
<field context2="속성 2에 있는 컨텍스트 메모">번역2용</field>
<context3>요소 2에 있는 컨텍스트 메모</context3>
</element>

</root>
  • 상위 요소의 속성 (컨텍스트 1): ../@context1

  • 자체 요소의 속성 (컨텍스트 2): @context2

  • 형제 요소 (컨텍스트 3): ../context3

Elements&Attributes: //*을(를) 가져오는 경우 컨텍스트 메모의 콘텐츠도 소스 세그먼트로 가져옵니다. Elements&Attributes에서 일반 가져오기 시 컨텍스트 메모 요소/속성을 제외합니다.

도움이 되었습니까?

Sorry about that! In what way was it not helpful?

The article didn’t address my problem.
I couldn’t understand the article.
The feature doesn’t do what I need.
Other reason.

Note that feedback is provided anonymously so we aren't able to reply to questions.
If you'd like to ask a question, submit a request to our Support team.
Thank you for your feedback.