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

XPath (TMS)

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

XPathはXMLパス言語の略です。XMLドキュメント内の要素や属性をナビゲートするために使用できます。XPATHに不慣れな場合は、まずXPathチュートリアルを参照し、公式のXPATHドキュメントを学んでください。

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

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

  • ステップ内の軸

    • 対応可能

      ancestor、ancestor-or-self、attribute、child、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>とは異なります。

XPathの例1 と XPathの例2 (名前空間付き)は次のための例ファイルです:

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

    //* | //@*

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

    (<elem1 attribute1="translate" attribute2="翻訳しない"/>)

    //* | //@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="翻訳用のテキスト">

    //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 が 2015 年の 'updated' 属性を持っている場合、要素 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']//*

    • <Text> の要素のみを <Child> にインポートする:

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

    • 属性 <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 から要素 target をインポートしますが、属性 id に 'img' または 'extra' が含まれている場合は除きます:

    1. ファイルの例:

      <tu id="pages|content|extra"><ori xml:lang="en">コース1</ori><target xml:lang="lang">コース1</target></tu>

    2. XPATH の例:

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

  18. <comment><lis> を除くすべての要素をインポートします。ただし、<lis translate="true"> とその子孫は除きません:

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

  19. <comment> を除くすべての要素と、属性 <... attribute2="翻訳しない"> を持つ要素を除き、その子孫をインポートします:

    //*[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 を持つすべての属性をロックします。値は:戻る, メニュー, または 時間 とその子孫

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

いくつかの外部

コンテキストメモ

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

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

<?xml version-"1.0" encoding="utf-8"?>
<root>
<element context1="親要素1の属性のメモ - ../@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.