XQuery:需要过滤提示
给定像这样的 XML 文件记录,
<ADR-NSBG>
<timeline timestamp="2011-06-09T00:15:00">
<datum datum="SGC_at_bsNo-14___SignalingNetworkConnection_at_netId-4___Sip_at_networkRole-2">
<sbgSipTotalIncSipRequests>4314320</sbgSipTotalIncSipRequests>
<sbgSipTotalIncSipResponses>9040481</sbgSipTotalIncSipResponses>
<sbgSipTotalIncFailureResponses>2321242</sbgSipTotalIncFailureResponses>
<sbgSipTotalOutSipRequests>9136608</sbgSipTotalOutSipRequests>
<sbgSipTotalOutSipResponses>4643002</sbgSipTotalOutSipResponses>
<sbgSipTotalOutFailureResponses>1027420</sbgSipTotalOutFailureResponses>
<sbgSipIncommingProvisionalResponses>3433875</sbgSipIncommingProvisionalResponses>
<sbgSipOutgoingProvisionalResponses>1845750</sbgSipOutgoingProvisionalResponses>
</datum>
<datum datum="SGC_at_bsNo-13___SignalingNetworkConnection_at_netId-4___Sip_at_networkRole-2">
<sbgSipTotalIncSipRequests>4799739</sbgSipTotalIncSipRequests>
<sbgSipTotalIncSipResponses>9335965</sbgSipTotalIncSipResponses>
<sbgSipTotalIncFailureResponses>2415690</sbgSipTotalIncFailureResponses>
<sbgSipTotalOutSipRequests>9474295</sbgSipTotalOutSipRequests>
<sbgSipTotalOutSipResponses>5291708</sbgSipTotalOutSipResponses>
<sbgSipTotalOutFailureResponses>1149950</sbgSipTotalOutFailureResponses>
<sbgSipIncommingProvisionalResponses>3516298</sbgSipIncommingProvisionalResponses>
<sbgSipOutgoingProvisionalResponses>2190601</sbgSipOutgoingProvisionalResponses>
</datum>
</timeline>
</ADR-NSBG>
我想做的是获取 datum
元素的子元素的值。
所以,我编写了以下查询:
for $i in collection("/db/_DEMO/ADR-NSBG/sipTransactTM/2011/06/09")
let $TIME_FROM := "2011-06-09T00:15:00"
let $TIME_TO := "2011-06-09T00:45:00"
let $DATUM := "SGC_at_bsNo-13___SignalingNetworkConnection_at_netId-4___Sip_at_networkRole-2"
where ( $i/ADR-NSBG/timeline/@timestamp/string(.) >= $TIME_FROM and
$i/ADR-NSBG/timeline/@timestamp/string(.) <= $TIME_TO) and
( $i/ADR-NSBG/timeline/datum/@datum/string(.) = $DATUM )
order by $i/ADR-NSBG/timeline/@timestamp/string(.)
return $i/ADR-NSBG/timeline/datum
但是,问题是我无法在两个“数据”节点之间进行选择。 查询的结果是:
<datum datum="SGC_at_bsNo-14___SignalingNetworkConnection_at_netId-4___Sip_at_networkRole-2">
<sbgSipTotalIncSipRequests>4314320</sbgSipTotalIncSipRequests>
<sbgSipTotalIncSipResponses>9040481</sbgSipTotalIncSipResponses>
<sbgSipTotalIncFailureResponses>2321242</sbgSipTotalIncFailureResponses>
<sbgSipTotalOutSipRequests>9136608</sbgSipTotalOutSipRequests>
<sbgSipTotalOutSipResponses>4643002</sbgSipTotalOutSipResponses>
<sbgSipTotalOutFailureResponses>1027420</sbgSipTotalOutFailureResponses>
<sbgSipIncommingProvisionalResponses>3433875</sbgSipIncommingProvisionalResponses>
<sbgSipOutgoingProvisionalResponses>1845750</sbgSipOutgoingProvisionalResponses>
</datum>
<datum datum="SGC_at_bsNo-13___SignalingNetworkConnection_at_netId-4___Sip_at_networkRole-2">
<sbgSipTotalIncSipRequests>4799739</sbgSipTotalIncSipRequests>
<sbgSipTotalIncSipResponses>9335965</sbgSipTotalIncSipResponses>
<sbgSipTotalIncFailureResponses>2415690</sbgSipTotalIncFailureResponses>
<sbgSipTotalOutSipRequests>9474295</sbgSipTotalOutSipRequests>
<sbgSipTotalOutSipResponses>5291708</sbgSipTotalOutSipResponses>
<sbgSipTotalOutFailureResponses>1149950</sbgSipTotalOutFailureResponses>
<sbgSipIncommingProvisionalResponses>3516298</sbgSipIncommingProvisionalResponses>
<sbgSipOutgoingProvisionalResponses>2190601</sbgSipOutgoingProvisionalResponses>
</datum>
我想问你的是:为什么语句 ( $i/ADR-NSBG/timeline/datum/@datum/string(.) = $DATUM )
会这样做不工作?
Given XML file-record like this
<ADR-NSBG>
<timeline timestamp="2011-06-09T00:15:00">
<datum datum="SGC_at_bsNo-14___SignalingNetworkConnection_at_netId-4___Sip_at_networkRole-2">
<sbgSipTotalIncSipRequests>4314320</sbgSipTotalIncSipRequests>
<sbgSipTotalIncSipResponses>9040481</sbgSipTotalIncSipResponses>
<sbgSipTotalIncFailureResponses>2321242</sbgSipTotalIncFailureResponses>
<sbgSipTotalOutSipRequests>9136608</sbgSipTotalOutSipRequests>
<sbgSipTotalOutSipResponses>4643002</sbgSipTotalOutSipResponses>
<sbgSipTotalOutFailureResponses>1027420</sbgSipTotalOutFailureResponses>
<sbgSipIncommingProvisionalResponses>3433875</sbgSipIncommingProvisionalResponses>
<sbgSipOutgoingProvisionalResponses>1845750</sbgSipOutgoingProvisionalResponses>
</datum>
<datum datum="SGC_at_bsNo-13___SignalingNetworkConnection_at_netId-4___Sip_at_networkRole-2">
<sbgSipTotalIncSipRequests>4799739</sbgSipTotalIncSipRequests>
<sbgSipTotalIncSipResponses>9335965</sbgSipTotalIncSipResponses>
<sbgSipTotalIncFailureResponses>2415690</sbgSipTotalIncFailureResponses>
<sbgSipTotalOutSipRequests>9474295</sbgSipTotalOutSipRequests>
<sbgSipTotalOutSipResponses>5291708</sbgSipTotalOutSipResponses>
<sbgSipTotalOutFailureResponses>1149950</sbgSipTotalOutFailureResponses>
<sbgSipIncommingProvisionalResponses>3516298</sbgSipIncommingProvisionalResponses>
<sbgSipOutgoingProvisionalResponses>2190601</sbgSipOutgoingProvisionalResponses>
</datum>
</timeline>
</ADR-NSBG>
What I would like to do is to get the values of the children of the datum
element.
so, I have written the following query:
for $i in collection("/db/_DEMO/ADR-NSBG/sipTransactTM/2011/06/09")
let $TIME_FROM := "2011-06-09T00:15:00"
let $TIME_TO := "2011-06-09T00:45:00"
let $DATUM := "SGC_at_bsNo-13___SignalingNetworkConnection_at_netId-4___Sip_at_networkRole-2"
where ( $i/ADR-NSBG/timeline/@timestamp/string(.) >= $TIME_FROM and
$i/ADR-NSBG/timeline/@timestamp/string(.) <= $TIME_TO) and
( $i/ADR-NSBG/timeline/datum/@datum/string(.) = $DATUM )
order by $i/ADR-NSBG/timeline/@timestamp/string(.)
return $i/ADR-NSBG/timeline/datum
But, the problem is that I cannot choose between the two "datum" nodes.
the result of the query is:
<datum datum="SGC_at_bsNo-14___SignalingNetworkConnection_at_netId-4___Sip_at_networkRole-2">
<sbgSipTotalIncSipRequests>4314320</sbgSipTotalIncSipRequests>
<sbgSipTotalIncSipResponses>9040481</sbgSipTotalIncSipResponses>
<sbgSipTotalIncFailureResponses>2321242</sbgSipTotalIncFailureResponses>
<sbgSipTotalOutSipRequests>9136608</sbgSipTotalOutSipRequests>
<sbgSipTotalOutSipResponses>4643002</sbgSipTotalOutSipResponses>
<sbgSipTotalOutFailureResponses>1027420</sbgSipTotalOutFailureResponses>
<sbgSipIncommingProvisionalResponses>3433875</sbgSipIncommingProvisionalResponses>
<sbgSipOutgoingProvisionalResponses>1845750</sbgSipOutgoingProvisionalResponses>
</datum>
<datum datum="SGC_at_bsNo-13___SignalingNetworkConnection_at_netId-4___Sip_at_networkRole-2">
<sbgSipTotalIncSipRequests>4799739</sbgSipTotalIncSipRequests>
<sbgSipTotalIncSipResponses>9335965</sbgSipTotalIncSipResponses>
<sbgSipTotalIncFailureResponses>2415690</sbgSipTotalIncFailureResponses>
<sbgSipTotalOutSipRequests>9474295</sbgSipTotalOutSipRequests>
<sbgSipTotalOutSipResponses>5291708</sbgSipTotalOutSipResponses>
<sbgSipTotalOutFailureResponses>1149950</sbgSipTotalOutFailureResponses>
<sbgSipIncommingProvisionalResponses>3516298</sbgSipIncommingProvisionalResponses>
<sbgSipOutgoingProvisionalResponses>2190601</sbgSipOutgoingProvisionalResponses>
</datum>
What I would like to ask you is : Why the statement ( $i/ADR-NSBG/timeline/datum/@datum/string(.) = $DATUM )
does not work ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在
where
子句中,您使用 datum 元素过滤for
子句的 $i 元素。您没有过滤数据元素。该表达式:
解析为:
这是正确的。因此,选择了$i元素。之后,return 子句中的表达式会选择包含的时间轴元素的两个子元素:
如何过滤数据元素
如果您只想选择具有特定字符串的数据,则需要过滤返回子句:
Whithin the
where
clause you are filtering the $i elements of thefor
clause by using the datum element. You are not filtering the datum elements.This expression:
is resolved to:
which is true. Therefore, the $i element is selected. After that, the expression in the return clause selects both child elements of the contained timeline element:
How to filter the datum elements
If you want to select only the datum with a specific string, you need to filter in the return clause: