使用cts:query检查属性的存在

时间:2014-01-29 14:32:42

标签: marklogic

cts:element-query(xs:QName("elm"),cts:and-query(()))会提供元素 elm 所在的所有片段。

同样,如果我想要在 elm 下出现属性(例如 atr )的所有文档,我还需要做什么?

cts:element-attribute-value-query()要求我传递一个值以匹配属性值。但我想只检查属性的存在,而不管它包含什么值。

2 个答案:

答案 0 :(得分:3)

您可以通过简单的cts:element-attribute-value-query

来完成
# Create a set of fitted values.

library(effects)

food.min <- round(min(model$model$LogFood), 3)
food.max <- round(max(model$model$LogFood), 3)

eff <- effect("LogPesticide:LogFood", model, 
              xlevels = list(LogPesticide = seq(min(model$model$LogPesticide), max(model$model$LogPesticide), length = 100),
                             LogFood = c(food.min, food.max)))

eff2 <- as.data.frame(eff)


# Find fitted values closest to 0.5 when LogFood is minimal and maximal.

fit.min <- which.min(abs(eff2$fit[eff2$LogFood == food.min] - 0.5))
fit.min <- eff2$fit[eff2$LogFood == food.min][fit.min]

fit.max <- which.min(abs(eff2$fit[eff2$LogFood == food.max] - 0.5))
fit.max <- eff2$fit[eff2$LogFood == food.max][fit.max]


# Use those fitted values to predict the LC50s.

lc50.min <- eff2$LogPesticide[eff2$fit == fit.min & eff2$LogFood == food.min]
lc50.max <- eff2$LogPesticide[eff2$fit == fit.max & eff2$LogFood == food.max]


# Plot the results.

plot(fit ~ LogPesticide, data = eff2[eff2$LogFood == round(min(model$model$LogFood), 3),], type = "l")
lines(fit ~ LogPesticide, data = eff2[eff2$LogFood == round(max(model$model$LogFood), 3),], col = "red")
points(y = 0.5, x = lc50.min, pch = 19)
points(y = 0.5, x = lc50.max, pch = 19, col = "red")

如果您未在数据库中设置通配符搜索为true,则还需要在cts中显式提供通配符启用搜索:element-attribute-value-query

cts:element-attribute-value-query(
xs:QName('element'), xs:QName('attribute'), '*'))  

有关详细信息,请查看cts:element-attribute-value-query

答案 1 :(得分:1)

尝试使用通配符。元素和属性之间的一个区别是元素可以为空。属性不能,因此它们应始终匹配通配符。您可能需要启用一些字符索引才能获得最佳性能。

cts:element-attribute-value-query(
  xs:QName('div'), xs:QName('id'), '*'))