インポートユーティリティ

XPath (TMS)

本コンテンツはPhrase Language AIの機械翻訳により、英語から翻訳されています。

XPathはXML Path Languageの略です。XMLドキュメント内の要素や属性をナビゲートするために使用できます。XPATHが初めての場合は、まず XPathチュートリアル を参照し、公式の XPATHドキュメント を学習してください。

AIチャットボットは、Xpathの生成と検証に非常に効果的です。

XPath 1.0のサブセットが以下の制限付きでサポートされています:

  • ステップ内の軸

    • 対応可能:

      ancestor、ancestor-or-self、attribute、子、descendant、descendant-or-self

    • 非対応:

      following、preceding、following-sibling、preceding-sibling、namespace

  • 述語

    • 対応可能:

      現在のノードまたはその祖先ノードとそのプロパティ(属性、名前空間)に関する条件

    • 非対応(例):

      位置番号、軸 child::、descendant、descendant-or-self、following::、preceding::、following-sibling::、preceding-sibling::、関数 last()

基本ルール

  • パスで /// を使用

  • 名前でシングルクォート ' ' を使用

  • リクエストの結合にパイプ | を使用

  • 名前は大文字と小文字を区別します:<Body><body> とは異なります

**Examples**

XPath 例 1 および XPath 例 2 (名前空間付き) は、以下の例ファイルです:

  1. すべての要素とすべての属性をインポートする

    //* | //@*

  2. すべての要素と attribute1 の値をインポートする

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

    //* | //@attribute1

  3. 子要素のすべての子孫をインポートする

    //Child//*

  4. 属性 translate='true' の場合のみ、要素 lis とその子孫をインポートする 

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

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

  5. 要素の属性が translate='true' である場合、すべての要素と子孫をインポートする

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

  6. 要素 Data の属性 Text の値をインポートする

    <Data Text="Text for translation">

    //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\">Do not translate)

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

  10. 属性 translate='false' を持つ要素 'lis' とその子孫を除外する

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

    //*[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>

    • <子> 内のすべての要素をインポートします:

      //*[local-name()='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'>translate this</Child>

    • translate属性が1である場合、要素 <子> をインポートします: //*[local-name()=\"Child\"][@*[local-name()='translate']='1']

    • translate=true属性を持つすべての要素をインポートします: //*[@*[local-name()='translate']='true']

  17. 名前空間を持つXML。要素 tu から訳文要素をインポートしますが、属性IDに 'img' または 'extra' が含まれる場合は除外します:

    1. ファイル例:

      <tu id=\"pages|コンテンツ|extra\"><ori xml:lang=\"en\">Course one</ori><訳文 xml:lang=\"lang\">Course one</訳文></tu>

    2. XPATH例:

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

  18. <lis translate=\"true\"> とその子孫を除き、<comment><lis> 以外のすべての要素をインポートします:

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

  19. <comment> を除き、属性 <... attribute2=\"Do not translate\"> を持つ要素とその子孫以外のすべての要素をインポートします:

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

  20. 属性 varNameglossName の値をインポートします。ただし、その祖先が属性 attribute1='translate' または attribute1='edit' を持っている場合に限ります:

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

  21. 属性 Name= BackMenu、または 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'])]

    この場合、すべてをインポートし、インポートに不要な属性をロックする方が良い場合があります。セグメントがロック済になったら、エディタで原文を訳文にコピーして、オリジナルを翻訳に転送します。

    1. 属性 Name の値が BackMenu、または Time であるすべての要素とその子孫をロックします:

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

    2. Name のすべての属性のうち、値が BackMenu、または Time であるものとその子孫をロックします

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

いくつかの外部 examples

コンテキストメモ

コンテキストメモは、翻訳済セグメントにインポートできます。

このサンプルには3つの例があります:

<?xml version-"1.0" encoding="utf-8"?>
<root>
<element context1="Note in attribute of parentElement 1 - select ../@context1">
<field context2=\"属性 1 のコンテキストメモ - 選択 @context2\" >翻訳用 1</field>
<context3>要素 1 のコンテキストメモ - 選択 ../context3</context3>
</element>

<element context1=\"親要素 2 の属性のコンテキストメモ\">
<field context2=\"属性 2 のコンテキストメモ\">翻訳用 2</field>
<context3>要素 2 のコンテキストメモ</context3>
</element>

</root>
  • 親要素の属性 (コンテキスト 1): ../@context1

  • 自己要素の属性 (コンテキスト 2): @context2

  • 兄弟要素 (コンテキスト 3): ../context3

要素と属性: //* をインポートする場合、コンテキストメモのコンテンツも原文セグメントにインポートされます。要素と属性の一般的なインポートからコンテキストメモの要素/属性を除外します。

この記事は役に立ちましたか?

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.