XQuery : in need of a filtering tip
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</sbgSip开发者_开发知识库TotalOutSipResponses>
<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 ?
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]
精彩评论