# predicate 說明 predicate 詞彙的相關意思與實務中的使用方式 <https://hackmd.io/@hacktionary/term-predicate> ## 內容大綱 [TOC] ## <ruby>名詞<rp>(</rp><rt>Noun</rt><rp>)</rp></ruby> ### 條件式 #### 例句 > The expression "." (an abbreviation for "self::node()") is most commonly used within a **predicate** to refer to the currently selected node. For example, `h3[.='See also']` selects an element called `h3` in the current context, whose text content is `See also`. > 「.」表達式(「self::node()」的簡寫)通常於一個**條件式**之中被使用以參照當前被選取的節點。例如,「h3[.='See also']」表達式於當前情境中選取一個文字內容為 See also 的一個叫做「h3」的元素。 > ——摘錄自 [Axis specifiers - XPath - Wikipedia](https://en.wikipedia.org/wiki/XPath#Axis_specifiers) [OpenAI 平台(gpt-4-turbo)參考翻譯與詞彙在情境中的說明](https://platform.openai.com/playground/p/5cTvrp2BKu6BuJzXwsm1ytWw?mode=chat): > Here is the translation of the specified passage into the Taiwan variant of Traditional Chinese: > > 表示式「.」(是「self::node()」的縮寫)常常在**預言條件**中使用,用來指代目前選取的節點。例如,`h3[.='See also']` 選取當前上下文中名為 `h3` 的元素,其文字內容為「See also」。 > > The emphasized term "predicate" in the original passage is translated as "預言條件" in Traditional Chinese. In the context of this passage, "predicate" refers to a condition used within the XPath query to filter elements or nodes. It specifies a criterion that must be met for a node to be selected or considered in the query result. In XML and XPath, predicates are usually placed inside square brackets following an element or node to narrow down the search, in this case, ensuring the selected `h3` element has the exact text content "See also". Google Gemini(2.0 Flash) 參考翻譯與詞彙在情境中的說明: > 以下是翻譯成台灣繁體中文的結果: > >>表達式"."("self::node()"的縮寫)最常在**述詞**中使用,以指稱目前選取的節點。例如,`h3[.='See also']`會選取目前情境中名為`h3`的元素,其文字內容為`See also`。 > > 關於原文中強調的術語「**predicate**」(述詞)的解釋: > > 在XPath(XML路徑語言)中,**述詞 (predicate)** 是一種用於篩選節點集合的表達式。它位於方括號 `[...]` 內,用於指定選擇節點的條件。 > > 簡單來說,述詞就像一個過濾器,它允許你根據節點的屬性、內容、位置等特徵,從一組節點中選擇出符合特定條件的節點。 > > 例如,在 `h3[.='See also']` 這個例子中,`[.='See also']` 就是一個述詞。它表示「選擇文字內容等於 'See also' 的節點」。 > > - `.` 代表目前選取的節點。 > - `=` 是一個比較運算符,用於檢查兩個值是否相等。 > - `'See also'` 是一個字串文字。 > > 因此,整個表達式 `h3[.='See also']` 的意思是「在目前情境中,選擇所有名為 `h3` 的元素,並且這些元素的文字內容必須完全等於 'See also'」。 > > 總結來說,述詞在XPath中扮演著至關重要的角色,它使得我們可以精確地選擇出我們需要的節點,從而實現對XML文檔的精確查詢。 --- 本文件為[《Hacktionary》專案](https://hackmd.io/@hacktionary/home)的衍生作品,以[《Creative Commons 姓名標示-相同方式分享》授權條款第 4.0 國際版](https://creativecommons.org/licenses/by-sa/4.0/deed.zh_TW)或其任意更近期版本釋出供大眾於授權範圍內自由使用 如參與本平台的內容實作視同為將您的內容以相同授權條款釋出 部份內容為基於合理使用(fair use)原則使用,使用方式請參閱其註明之來源與作者 <style> /* 調大旁註文字的字元大小 */ rt{ font-size: 10pt; } </style>