2013-12-09 49 views
1

我的XML數據的某個元素應符合下列條件精確ONE:的XPath:嵌套/複雜條件

1)它有一個@when屬性而已。

2.)它有@ when-iso屬性,沒有別的。

3.)它既有@ notBefore-iso也有@ notAfter-iso屬性,但既沒有@when也沒有@ when-iso屬性。

我嘗試使用schematron來測試,但我無法創建匹配的xpath表達式。

我試圖

<assert test="@when or @when-iso or (not(@when) and not(@when-iso) and @notBefore-iso and @notAfter-iso)"> 

,但不起作用。很顯然,括號中的內容被忽略。那麼,我該如何構建複雜/嵌套的條件表達式呢?

回答

3

應該針對你的情況的示例:

<assert test="(@when and count(@*)=1) or (@when-iso and count(@*)=1) or (@notBefore-iso and @notAfter-iso and count(@*)=2)"/>