簡體   English   中英

XPath中的邏輯OR? 為什么不是 工作?

[英]Logical OR in XPath? Why isn't | working?

我有一個XSLT模板,它可以計算各個級別的主題,用於在DITA項目中使用編號標記這些主題。

<xsl:template match="*[contains(@class, ' bookmap/chapter ')] | *[contains(@class, ' map/topicref ')] [not(ancestor-or-self::*[contains(@class,' bookmap/frontmatter ')])]" mode="topicTitleNumber"> 
    <xsl:number format="1 " count="*[contains(@class, ' map/topicref ')] [not(ancestor-or-self::*[contains(@class,' bookmap/frontmatter ')])] | *[contains(@class, ' bookmap/chapter ')]" level="multiple"/> 
</xsl:template> 

我正在嘗試添加一個額外的排除,但是當topicref類具有一個帶有outputclassnoNum類的title元素時,它outputclassnoNum

<xsl:template match="*[contains(@class, ' bookmap/chapter ')] | *[contains(@class, ' map/topicref ')] [not(ancestor-or-self::*[contains(@class,' bookmap/frontmatter ')])]" mode="topicTitleNumber"> 
    <xsl:number format="1 " count="*[contains(@class, ' map/topicref ')] [not(ancestor-or-self::*[contains(@class,' bookmap/frontmatter ')] | *[contains(title/@outputclass, 'noNum')])] | *[contains(@class, ' bookmap/chapter ')]" level="multiple"/> 
</xsl:template> 

如上所示,我添加了| *[contains(title/@outputclass, 'noNum')] | *[contains(title/@outputclass, 'noNum')]在第一個not語句之后,認為這將作為一個附加條件,在調用模板時count調用將跳過(即...不是祖先 - or-self with [criteria]或title titleclass屬性為'noNum'的主題...) 但是看來我添加的標准作為一些模板匹配和計數處理。

假設我在最后一點上是正確的,我相信我需要將這個條件放在它自己的'not'語句中,但是我不確定如何使用XPath中已存在的條件來做到這一點。

在XPath中| 是一個集合聯合運算符 ,而不是邏輯OR。

聯盟運營商, |

XPath 1.0

| operator計算其操作數的並集,該操作數必須是節點集。

XPath 2.0+

union| 運營商是等同的。 它們將兩個節點序列作為操作數,並返回包含在任一操作數中出現的所有節點的序列。


邏輯OR, or

使用or代替邏輯OR


復雜的XPath仍然無法正常工作?

將其分解為更小的部分:

  1. //*[contains(@class, ' bookmap/chapter ')]選擇你期望的嗎? 分別對邏輯表達式的每個最基本部分重復。

  2. 將這些經過單獨驗證的術語或謂詞一次一個地結合起來,觀察沿途的每一步,都不會出現意外。

  3. 在合並附加條款之前,修復預期結果與實際結果之間的任何差異。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM