XQuery:需要过滤提示

发布于 2024-11-17 23:41:29 字数 4400 浏览 1 评论 0原文

给定像这样的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

握住你手 2024-11-24 23:41:29

where 子句中,您使用 datum 元素过滤 for 子句的 $i 元素。您没有过滤数据元素。

该表达式:

( $i/ADR-NSBG/timeline/datum/@datum/string(.) = $DATUM )

解析为:

(
 "SGC_at_bsNo-14___SignalingNetworkConnection_at_netId-4___Sip_at_networkRole-2",
 "SGC_at_bsNo-13___SignalingNetworkConnection_at_netId-4___Sip_at_networkRole-2"
) =
 "SGC_at_bsNo-13___SignalingNetworkConnection_at_netId-4___Sip_at_networkRole-2"

这是正确的。因此,选择了$i元素。之后,return 子句中的表达式会选择包含的时间轴元素的两个子元素:

$i/ADR-NSBG/timeline/datum

如何过滤数据元素

如果您只想选择具有特定字符串的数据,则需要过滤返回子句:

$i/ADR-NSBG/timeline/datum[@datum eq $DATUM]

Whithin the where clause you are filtering the $i elements of the for clause by using the datum element. You are not filtering the datum elements.

This expression:

( $i/ADR-NSBG/timeline/datum/@datum/string(.) = $DATUM )

is resolved to:

(
 "SGC_at_bsNo-14___SignalingNetworkConnection_at_netId-4___Sip_at_networkRole-2",
 "SGC_at_bsNo-13___SignalingNetworkConnection_at_netId-4___Sip_at_networkRole-2"
) =
 "SGC_at_bsNo-13___SignalingNetworkConnection_at_netId-4___Sip_at_networkRole-2"

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:

$i/ADR-NSBG/timeline/datum

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:

$i/ADR-NSBG/timeline/datum[@datum eq $DATUM]
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文