Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   XML (http://www.velocityreviews.com/forums/f32-xml.html)
-   -   XQuery how to keep order of elements? (http://www.velocityreviews.com/forums/t170280-xquery-how-to-keep-order-of-elements.html)

paul.rusu@gmail.com 12-06-2005 12:30 PM

XQuery how to keep order of elements?
 
I have a element "v" wich has different types of objects a,b,c.

and i do:
for $x in $doc/v/a where ... return $x
for $x in $doc/v/b where ... return $x
for $x in $doc/v/c where ... return $x
for each of them to filter them by conditions.
This way i get all the objects of type a, than all objects of type b,
than all obj of type c.

But I would like to have them in the original (mixed) order.
How to keep this order. Someone told me I could add a order by field.
But still I have to say "for each element whatever type, if it is of
type a than, else..". How do I say this in Xquery?

Paul


Priscilla Walmsley 12-07-2005 12:51 PM

Re: XQuery how to keep order of elements?
 
Hi Paul,

You've got (at least) 2 choices. You can process them all together in
one FLWOR expression, as in:

for $x in $doc/v/(a|b|c) where ... return $x

That will process them in the order they appear in the document. If you
want to do something different with each of the 3 element types, you
could put an "if" expression in your where and/or return clauses to
check if it's a, b or c, as in:

if ($x instance of element(a))
then (: something :)
else if ($x instance of element(b))
then (: something :)
else if ($x instance of element(c))
then (: something :)
else ()

A slightly more compact alternative to that is the typeswitch
expression:

typeswitch($x)
case element(a) return (: something :)
case element(b) return (: something :)
case element(c) return (: something :)
default return (: something :)


Another alternative for keeping document order is to keep the 3 separate
FLWOR expressions and sort them back into document order outside the
scope of those, e.g.

let $all :=
(for $x in $doc/v/a where ... return $x,
for $x in $doc/v/b where ... return $x,
for $x in $doc/v/c where ... return $x)
return $all/.

This will only work if you are actually returning the a, b and c
elements, not their text content or children or whatever. The "/." in
the return clause causes the processor to automatically sort the
elements back to document order.

An order by clause won't help you here - that's only for sorting on the
contents of an element or attribute.

Hope that helps,
Priscilla
----------------------------------
Priscilla Walmsley
Author, Definitive XML Schema
Definitive XQuery
http://www.datypic.com
----------------------------------

*** Sent via Developersdex http://www.developersdex.com ***

paul.rusu@gmail.com 12-07-2005 05:11 PM

Re: XQuery how to keep order of elements?
 
Priscilla,

Thanks for the reply. I'll check out the code.
I'm glad someone answered so I 'm going to ask you to just 2 more
things:
- I want to search by for example
"a*b" and foudn results could be ab, acb, acdefb. What is the closest
regular expersion for * that i can use in match, or contains to do
this.

And now a delicate problem:
I can't get the syntax right. It seems ok but I still get errors.
The return ..<a>.. else.. for.. return stuff are reported as "invalid
tokens".
I just want to do a if else in a for with for inside but the syntax is
tricky. I tried a lot of posiblities.
for $x in $doc

if ($x resp condition) then
<a>
{
for $y in $x/Son
return $y;
}
</a>
else
<b>
{
for $y in $x/Son2
return $y;
}
</b>

Paul


Priscilla Walmsley 12-07-2005 05:35 PM

Re: XQuery how to keep order of elements?
 
Hi Paul,

1. a.*b should match your examples. Only the "matches" function will use
regexes, not the "contains" function.

2. You are missing a return for the first for, and the semicolons should
not be there. So, if you change it to:

for $x in $doc
return
if ($x resp condition) then
<a>
{
for $y in $x/Son
return $y
}
</a>
else
<b>
{
for $y in $x/Son2
return $y
}
</b>

I assume "$x resp condition" is your shorthand and not your actual
expression that appears there.

Hope that helps,
Priscilla

----------------------------------
Priscilla Walmsley
Author, Definitive XML Schema
Definitive XQuery
http://www.datypic.com
----------------------------------

*** Sent via Developersdex http://www.developersdex.com ***

paul.rusu@gmail.com 12-08-2005 07:25 AM

Re: XQuery how to keep order of elements?
 
OK. Thanks.

Btw, you are an author, you must know all the tircks in the book. How
should you do "xor"?
I have a big condition (exclude_items=0 and .. (big condition) ) and
for (exclude_items=1 and (big condition)). How should I do this without
placing the huge condition (
pages) twice?

Paul


Priscilla Walmsley 12-09-2005 03:25 PM

Re: XQuery how to keep order of elements?
 
Hi,

You could assign the big condition to a variable using a let clause, as
in:

let $cond := (big condition)
return
if ((exclude_items = 0 and $cond) or
(exclude_items = 1 and not($cond)))
then ...
else ...


Hope that helps,
Priscilla

----------------------------------
Priscilla Walmsley
Author, Definitive XML Schema
http://www.datypic.com
----------------------------------

*** Sent via Developersdex http://www.developersdex.com ***

paul.rusu@gmail.com 12-12-2005 07:56 AM

Re: XQuery how to keep order of elements?
 
Priscilla,

You've been so helpfull.
1)I tried to apply the "typeswitch " thing you showed me but it's now
working.
I have syntax problems when it comes to if (cond) return $x.
Here is my code. You don't have to understand it just please look at
the typeswitch ($y) case element(..) if (cond) then $x else ( )
>From a working code I just changed "for .. where .." to "case elment

(..) return if (....) then .. else..". So for each case element the
"return if " sintax is the problem.
2)Also can you give me a complete short example on a sample xml of the
condition negation with "let" you wrote about in the last email.

let $doc_name:="can.xml"
let $exclude_items:=0
let $after_startstoptrace:=0
let $after_comprimitive_logicallink_name:=0
let $after_comprimitive_name:=0
let $after_comprimitive_id:=0
let $logical_link_name:="CAN1.DiagCan"
let $include_complete_result_pdu_request:=0
let $include_complete_result_parameter_value_request:= 0
let $include_complete_result_parameter_type_request:=0
let $include_complete_result_parameter_name_request:=0
let $include_complete_result_error_code_request:=0
let $include_complete_result_error_severity_request:=0
let $include_complete_result_pdu_response:=0
let $include_complete_result_parameter_value_response: =0
let $include_complete_result_parameter_type_response:= 0
let $include_complete_result_parameter_name_response:= 0
let $include_complete_result_error_code_response:=0
let $include_complete_result_error_severity_response:= 0
let $include_complete_result_pdu_both:=0
let $include_complete_result_parameter_value_both:=0
let $include_complete_result_parameter_type_both:=0
let $include_complete_result_parameter_name_both:=0
let $include_complete_result_error_code_both:=0
let $include_complete_result_error_severity_both:=0
let $request_pdu:=0
let $request_parameter_value:=0
let $request_parameter_type:=0
let $request_parameter_name:=1
let $request_error_code:=0
let $request_error_severity:=0
let $response_pdu:=0
let $response_parameter_value:=0
let $response_parameter_type:=0
let $response_parameter_name:=0
let $response_error_code:=0
let $response_error_severity:=0
let $both_pdu:=0
let $both_parameter_value:=0
let $both_parameter_type:=0
let $both_parameter_name:=0
let $both_error_code:=0
let $both_error_severity:=0

let $comprimitive_name:="readDataByLocalID"
let $comprimitive_id:=""
let $pdu_byte_pattern_request:="8"
let $parameter_name_request:="$diagnosticMode^"
let $parameter_type_request:=""
let $parameter_value_request:=""
let $error_code_request:=""
let $error_severity_request:="w"
let $pdu_byte_pattern_response:=""
let $parameter_name_response:=""
let $parameter_type_response:="3"
let $parameter_value_response:=""
let $error_code_response:=""
let $error_severity_response:="w"
let $pdu_byte_pattern_both:=""
let $parameter_name_both:=""
let $parameter_type_both:="3"
let $parameter_value_both:=""
let $error_code_both:=""
let $error_severity_both:="w"

for $x in doc ($doc_name)/ProcessValueTrace/Trace
return

<ProcessValueTrace> <Trace>

{for $y in
$x/(StartTrace|OpenComPrimitive|DtsResult|CloseComPri mitive|StopTrace)
return
typeswitch($y)
case element(StartTrace)
return
if( $after_startstoptrace=1 and $exclude_items=0) then
(: sintax problem here :)
return $y
else ()

case element(OpenComPrimitive)
return

if(
($exclude_items=0 and
($after_comprimitive_logicallink_name=1 or $after_comprimitive_name=1
or
$after_comprimitive_id=1) and

(
( $after_comprimitive_logicallink_name=0 or
($ after_comprimitive_logicallink_name=1 and
(
some $z in $y/LogicalLink satisfies
(
contains($z/ShortName, string($logical_link_name))
)
)
)
)
and
( $after_comprimitive_name=0 or
($ after_comprimitive_name=1 and
(
contains($y/ShortName, string($comprimitive_name))
)
)
)
and
( $after_comprimitive_id=0 or
($ after_comprimitive_id=1 and
(
contains($y/ID, string($comprimitive_id))
)
)
)
)
)
) then
(: sintax problem here :)
return $y
else ()

case element(DtsResult)
return
{
if
(
(

(: start include complete conditions in DtsResult :)
(
($include_complete_result_pdu_request=1 and
( ($request_pdu=1)
and
(
some $xx in $y/DtsRequest satisfies
(
contains($xx/PDU, string($pdu_byte_pattern_request))
)
)
)
)

or
($include_complete_result_parameter_name_request=1 and
( ($request_pdu=1)
and
(
some $xx in $y/DtsRequest/DtsRequestParameter satisfies
(
matches($xx/ShortName, string($parameter_name_request))
)
)
)
)

or
($include_complete_result_parameter_value_request= 1 and
( ($request_parameter_value=1)
and
(
some $xx in $y/DtsRequest/DtsRequestParameter/DtsValue satisfies

(
contains($xx/Value, string($parameter_value_request))
)
)
)
)

or
($include_complete_result_parameter_type_request=1 and
( ($request_parameter_type=1)
and
(
some $xx in $y/DtsRequest/DtsRequestParameter/DtsValue satisfies

(
contains($xx/Type, string($parameter_type_request))
)
)
)
)

or
($include_complete_result_error_code_request=1 and
( ($request_error_code=1)
and
(
some $xx in $y/DtsRequest/DtsRequestParameter/DtsError satisfies

(
contains($xx/CodeDescription, string($error_code_request))
)
)
)
)
or
($include_complete_result_error_severity_request=1 and
( ($request_error_severity=1)
and
(
some $xx in $y/DtsRequest/DtsRequestParameter/DtsError satisfies

(
contains($xx/Severity, string($error_severity_request))
)
)
)
)
or
($include_complete_result_pdu_response=1 and
( ($response_pdu=1)
and
(
some $xx in $y/DtsResponse satisfies
(
contains($xx/PDU, string($pdu_byte_pattern_response))
)
)
)
)

or

($include_complete_result_parameter_name_response= 1 and
( ($response_pdu=1)
and
(
some $xx in $y/DtsResponse/DtsReponseParameter satisfies
(
contains($xx/ShortName, string($parameter_name_response))
)
)
)
)

or
($include_complete_result_parameter_value_response =1 and
( ($response_parameter_value=1)
and
(
some $xx in $y/DtsResponse/DtsResponseParameter/DtsValue
satisfies
(
contains($xx/Value, string($parameter_value_response))
)
)
)
)
or
($include_complete_result_parameter_type_response= 1 and
( ($response_parameter_type=1)
and
(
some $xx in $y/DtsResponse/DtsResponseParameter/DtsValue
satisfies
(
contains($xx/Type, string($parameter_type_response))
)
)
)
)
or
($include_complete_result_error_code_response=1 and
( ($response_error_code=1)
and
(
some $xx in $y/DtsResponse/DtsResponseParameter/DtsError
satisfies
(
contains($xx/CodeDescription, string($error_code_response))
)
)
)
)
or
($include_complete_result_error_severity_response= 1 and
( ($response_error_severity=1)
and
(
some $xx in $y/DtsResponse/DtsResponseParameter/DtsError
satisfies
(
contains($xx/Severity, string($error_severity_response))
)
)
)
)
or
($include_complete_result_pdu_both=1 and
( ($both_pdu=1)
and
(
(some $xx in $y/DtsRequest satisfies
(
contains($xx/PDU, string($pdu_byte_pattern_both))
))
and
(some $xx in $y/DtsResponse satisfies
(
contains($xx/PDU, string($pdu_byte_pattern_both))
))
)
)
)
or
($include_complete_result_parameter_name_both=1 and
( ($both_pdu=1)
and
(
(some $xx in $y/DtsRequest/DtsRequestParameter satisfies
(
contains($xx/ShortName, string($parameter_name_both))
))
and
(some $xx in $y/DtsResponse/DtsResponseParameter satisfies
(
contains($xx/ShortName, string($parameter_name_both))
))
)
)
)
or
($include_complete_result_parameter_value_both=1 and
( ($both_parameter_value=1)
and
(
(some $xx in $y/DtsRequest/DtsRequestParameter/DtsValue
satisfies
(
contains($xx/Value, string($parameter_value_both))
))
and
(some $xx in $y/DtsResponse/DtsResponseParameter/DtsValue
satisfies
(
contains($xx/Value, string($parameter_value_both))
))
)
)
)
or
($include_complete_result_parameter_type_both=1 and
( ($both_parameter_type=1)
and
(
(some $xx in $y/DtsRequest/DtsRequestParameter/DtsValue
satisfies
(
contains($xx/Type, string($parameter_type_both))
))
and
(some $xx in $y/DtsResponse/DtsResponseParameter/DtsValue
satisfies
(
contains($xx/Type, string($parameter_type_both))
))
)
)
)

or
($include_complete_result_error_code_both=1 and
( ($both_error_code=1)
and
(
(some $xx in $y/DtsRequest/DtsRequestParameter/DtsError
satisfies
(
contains($xx/CodeDescription, string($error_code_both))
))
and
(some $xx in $y/DtsResponse/DtsResponseParameter/DtsError
satisfies
(
contains($xx/CodeDescription, string($error_code_both))
))
)
)
)
or
($include_complete_result_error_severity_both=1 and
( ($both_error_severity=1)
and
(
(some $xx in $y/DtsRequest/DtsRequestParameter/DtsError
satisfies
(
contains($xx/Severity, string($error_severity_both))
))
and
(some $xx in $y/DtsResponse/DtsResponseParameter/DtsError
satisfies
(
contains($xx/Severity, string($error_severity_both))
))
)
)
)
)(: end include complete conditions in DtsResult :)
or
(
(: start all non complete conditions in DtsResult :)

(: we must have some conditions :)
($request_pdu=1 or $request_parameter_name=1 or
$request_parameter_type=1 or
$request_parameter_value=1 or $request_error_code=1 or
$request_error_severity=1
or
$response_pdu=1 or $response_parameter_name=1 or
$response_parameter_type=1 or
$response_parameter_value=1 or $response_error_code=1 or
$response_error_severity=1
or
$both_pdu=1 or $both_parameter_name=1 or $both_parameter_type=1 or
$both_parameter_value=1 or $both_error_code=1 or
$both_error_severity=1)
and
($include_complete_result_pdu_request=1 or
($include_complete_result_pdu_request=0 and
(
($request_pdu=0 or
($request_pdu=1
and
(
some $xx in $y/DtsRequest satisfies
(
contains($xx/PDU, string($pdu_byte_pattern_request))
)
)
)
)
)
)
)
and
($include_complete_result_parameter_name_request=1 or
($include_complete_result_parameter_name_request=0 and
(
($request_parameter_name=0 or
($request_parameter_name=1
and
(
some $xx in $y/DtsRequest/DtsRequestParameter satisfies
(
contains($xx/ShortName, string($parameter_name_request))
)
)
)
)
)
)
)
and
($include_complete_result_parameter_value_request= 1 or
($include_complete_result_parameter_value_request= 0 and
(
($request_parameter_value=0 or
($request_parameter_value=1
and
(
some $xx in $y/DtsRequest/DtsRequestParameter/DtsValue
satisfies
(
contains($xx/Value, string($parameter_value_request))
)
)
)
)
)
)
)
and
($include_complete_result_parameter_type_request=1 or
($include_complete_result_parameter_type_request=0 and
(
($request_parameter_type=0 or
($request_parameter_type=1
and
(
some $xx in $y/DtsRequest/DtsRequestParameter/DtsValue
satisfies
(
contains($xx/Type, string($parameter_type_request))
)
)
)
)
)
)
)
and
($include_complete_result_error_code_request=1 or
($include_complete_result_error_code_request=0 and
(
($request_error_code=0 or
($request_error_code=1
and
(
some $xx in $y/DtsRequest/DtsRequestParameter/DtsError
satisfies
(
contains($xx/CodeDescription, string($error_code_request))
)
)
)
)
)
)
)
and
($include_complete_result_error_severity_request=1 or
($include_complete_result_error_severity_request=0 and
(
($request_error_severity=0 or
($request_error_severity=1
and
(
some $xx in $y/DtsRequest/DtsRequestParameter/DtsError
satisfies
(
contains($xx/Severity, string($error_severity_request))
)
)
)
)
)
)
)

and
($include_complete_result_pdu_response=1 or
($include_complete_result_pdu_response=0 and
(
($response_pdu=0 or
($response_pdu=1
and
(
some $xx in $y/DtsResponse satisfies
(
contains($xx/PDU, string($pdu_byte_pattern_response))
)
)
)
)
)
)
)
and
($include_complete_result_parameter_name_response= 1 or
($include_complete_result_parameter_name_response= 0 and
(
($response_parameter_name=0 or
($response_parameter_name=1
and
(
some $xx in $y/DtsResponse/DtsResponseParameter satisfies
(
contains($xx/ShortName, string($parameter_name_response))
)
)
)
)
)
)
)
and
($include_complete_result_parameter_value_response =1 or
($include_complete_result_parameter_value_response =0 and
(
($response_parameter_value=0 or
($response_parameter_value=1
and
(
some $xx in $y/DtsResponse/DtsResponseParameter/DtsValue
satisfies
(
contains($xx/Value, string($parameter_value_response))
)
)
)
)
)
)
)
and
($include_complete_result_parameter_type_response= 1 or
($include_complete_result_parameter_type_response= 0 and
(
($response_parameter_type=0 or
($response_parameter_type=1
and
(
some $xx in $y/DtsResponse/DtsResponseParameter/DtsValue
satisfies
(
contains($xx/Type, string($parameter_type_response))
)
)
)
)
)
)
)
and
($include_complete_result_error_code_response=1 or
($include_complete_result_error_code_response=0 and
(
($response_error_code=0 or
($response_error_code=1
and
(
some $xx in $y/DtsResponse/DtsResponseParameter/DtsError
satisfies
(
contains($xx/CodeDescription, string($error_code_response))
)
)
)
)
)
)
)
and
($include_complete_result_error_severity_response= 1 or
($include_complete_result_error_severity_response= 0 and
(
($response_error_severity=0 or
($response_error_severity=1
and
(
some $xx in $y/DtsResponse/DtsResponseParameter/DtsError
satisfies
(
contains($xx/Severity, string($error_severity_response))
)
)
)
)
)
)
)
and
($include_complete_result_pdu_both=1 or
($include_complete_result_pdu_both=0 and
(
($response_pdu=0 or
($response_pdu=1
and
(
(some $xx in $y/DtsResponse satisfies
(
contains($xx/PDU, string($pdu_byte_pattern_both))
))
and
(some $xx in $y/DtsRequest satisfies
(
contains($xx/PDU, string($pdu_byte_pattern_both))
))
)
)
)
)
)
)
and
($include_complete_result_parameter_name_both=1 or
($include_complete_result_parameter_name_both=0 and
(
($response_parameter_name=0 or
($response_parameter_name=1
and
(
(some $xx in $y/DtsResponse/DtsResponseParameter satisfies
(
contains($xx/ShortName, string($parameter_name_both))
))
and
(some $xx in $y/DtsRequest/DtsRequestParameter satisfies
(
contains($xx/ShortName, string($parameter_name_both))
))
)
)
)
)
)
)
and
($include_complete_result_parameter_value_both=1 or
($include_complete_result_parameter_value_both=0 and
(
($response_parameter_value=0 or
($response_parameter_value=1
and
(
(some $xx in $y/DtsResponse/DtsResponseParameter/DtsValue
satisfies
(
contains($xx/Value, string($parameter_value_both))
))
and
(some $xx in $y/DtsRequest/DtsRequestParameter/DtsValue
satisfies
(
contains($xx/Value, string($parameter_value_both))
))
)
)
)
)
)
)
and
($include_complete_result_parameter_type_both=1 or
($include_complete_result_parameter_type_both=0 and
(
($response_parameter_type=0 or
($response_parameter_type=1
and
(
(some $xx in $y/DtsResponse/DtsResponseParameter/DtsValue
satisfies
(
contains($xx/Type, string($parameter_type_both))
))
and
(some $xx in $y/DtsRequest/DtsRequestParameter/DtsValue
satisfies
(
contains($xx/Type, string($parameter_type_both))
))

)
)
)
)
)
)
and
($include_complete_result_error_code_both=1 or
($include_complete_result_error_code_both=0 and
(
($response_error_code=0 or
($response_error_code=1
and
(
(some $xx in $y/DtsResponse/DtsResponseParameter/DtsError
satisfies
(
contains($xx/CodeDescription, string($error_code_both))
))
and
(some $xx in $y/DtsRequest/DtsRequestParameter/DtsError
satisfies
(
contains($xx/CodeDescription, string($error_code_both))
))
)
)
)
)
)
)
and
($include_complete_result_error_severity_both=1 or
($include_complete_result_error_severity_both=0 and
(
($response_error_severity=0 or
($response_error_severity=1
and
(
(some $xx in $y/DtsResponse/DtsResponseParameter/DtsError
satisfies
(
contains($xx/Severity, string($error_severity_both))
))
and
(some $xx in $y/DtsRequest/DtsRequestParameter/DtsError
satisfies
(
contains($xx/Severity, string($error_severity_both))
))
)
)
)
)
)
)
) (: end all non complete conditions in DtsResult :)
)) then
return
<DtsResult>
{for $xx in $y/LogicalLink
return $xx
}
{for $xx in $y/ComPrimitive
return $xx
}
{for $xx in $y/Type
return $xx
}
{for $xx in $y/State
return $xx
}
{for $xx in $y/StateInfo
return $xx
}

{for $vv in $y/DtsRequest
where
(
(: start complete conditions in DtsRequest :)

($include_complete_result_pdu_request=1 and
( ($request_pdu=1)
and
(
some $xx in $y/DtsRequest satisfies
(
contains($xx/PDU, string($pdu_byte_pattern_request))
)
)
)
)

or
($include_complete_result_parameter_name_request=1 and
( ($request_pdu=1)
and
(
some $xx in $y/DtsRequest/DtsRequestParameter satisfies
(
contains($xx/ShortName, string($parameter_name_request))
)
)
)
)

or
($include_complete_result_parameter_value_request= 1 and
( ($request_parameter_value=1)
and
(
some $xx in $y/DtsRequest/DtsRequestParameter/DtsValue satisfies

(
contains($xx/Value, string($parameter_value_request))
)
)
)
)

or
($include_complete_result_parameter_type_request=1 and
( ($request_parameter_type=1)
and
(
some $xx in $y/DtsRequest/DtsRequestParameter/DtsValue satisfies

(
contains($xx/Type, string($parameter_type_request))
)
)
)
)

or
($include_complete_result_error_code_request=1 and
( ($request_error_code=1)
and
(
some $xx in $y/DtsRequest/DtsRequestParameter/DtsError satisfies

(
contains($xx/CodeDescription, string($error_code_request))
)
)
)
)
or
($include_complete_result_error_severity_request=1 and
( ($request_error_severity=1)
and
(
some $xx in $y/DtsRequest/DtsRequestParameter/DtsError satisfies

(
contains($xx/Severity, string($error_severity_request))
)
)
)
)
or
($include_complete_result_pdu_response=1 and
( ($response_pdu=1)
and
(
some $xx in $y/DtsResponse satisfies
(
contains($xx/PDU, string($pdu_byte_pattern_response))
)
)
)
)

or
($include_complete_result_parameter_name_response= 1 and
( ($response_pdu=1)
and
(
some $xx in $y/DtsResponse/DtsReponseParameter satisfies
(
contains($xx/ShortName, string($parameter_name_response))
)
)
)
)

or
($include_complete_result_parameter_value_response =1 and
( ($response_parameter_value=1)
and
(
some $xx in $y/DtsResponse/DtsResponseParameter/DtsValue
satisfies
(
contains($xx/Value, string($parameter_value_response))
)
)
)
)

or
($include_complete_result_parameter_type_response= 1 and
( ($response_parameter_type=1)
and
(
some $xx in $y/DtsResponse/DtsResponseParameter/DtsValue
satisfies
(
contains($xx/Type, string($parameter_type_response))
)
)
)
)

or
($include_complete_result_error_code_response=1 and
( ($response_error_code=1)
and
(
some $xx in $y/DtsResponse/DtsResponseParameter/DtsError
satisfies
(
contains($xx/CodeDescription, string($error_code_response))
)
)
)
)
or
($include_complete_result_error_severity_response= 1 and
( ($response_error_severity=1)
and
(
some $xx in $y/DtsResponse/DtsResponseParameter/DtsError
satisfies
(
contains($xx/Severity, string($error_severity_response))
)
)
)
)
or
($include_complete_result_pdu_both=1 and
( ($both_pdu=1)
and
(
(some $xx in $y/DtsRequest satisfies
(
contains($xx/PDU, string($pdu_byte_pattern_both))
))
and
(some $xx in $y/DtsResponse satisfies
(
contains($xx/PDU, string($pdu_byte_pattern_both))
))
)
)
)
or
($include_complete_result_parameter_name_both=1 and
( ($both_pdu=1)
and
(
(some $xx in $y/DtsRequest/DtsRequestParameter satisfies
(
contains($xx/ShortName, string($parameter_name_both))
))
and
(some $xx in $y/DtsResponse/DtsResponseParameter satisfies
(
contains($xx/ShortName, string($parameter_name_both))
))
)
)
)
or
($include_complete_result_parameter_value_both=1 and
( ($both_parameter_value=1)
and
(
(some $xx in $y/DtsRequest/DtsRequestParameter/DtsValue
satisfies
(
contains($xx/Value, string($parameter_value_both))
))
and
(some $xx in $y/DtsResponse/DtsResponseParameter/DtsValue
satisfies
(
contains($xx/Value, string($parameter_value_both))
))
)
)
)
or
($include_complete_result_parameter_type_both=1 and
( ($both_parameter_type=1)
and
(
(some $xx in $y/DtsRequest/DtsRequestParameter/DtsValue
satisfies
(
contains($xx/Type, string($parameter_type_both))
))
and
(some $xx in $y/DtsResponse/DtsResponseParameter/DtsValue
satisfies
(
contains($xx/Type, string($parameter_type_both))
))
)
)
)

or
($include_complete_result_error_code_both=1 and
( ($both_error_code=1)
and
(
(some $xx in $y/DtsRequest/DtsRequestParameter/DtsError
satisfies
(
contains($xx/CodeDescription, string($error_code_both))
))
and
(some $xx in $y/DtsResponse/DtsResponseParameter/DtsError
satisfies
(
contains($xx/CodeDescription, string($error_code_both))
))
)
)
)
or
($include_complete_result_error_severity_both=1 and
( ($both_error_severity=1)
and
(
(some $xx in $y/DtsRequest/DtsRequestParameter/DtsError
satisfies
(
contains($xx/Severity, string($error_severity_both))
))
and
(some $xx in $y/DtsResponse/DtsResponseParameter/DtsError
satisfies
(
contains($xx/Severity, string($error_severity_both))
))
)
)
)
)(: end complete conditions in DtsRequest :)
or
(
(: start all non complete conditions in DtsRequest :)

($request_pdu=1 or $request_parameter_name=1 or
$request_parameter_type=1 or
$request_parameter_value=1 or $request_error_code=1 or
$request_error_severity=1
or
$both_pdu=1 or $both_parameter_name=1 or $both_parameter_type=1 or
$both_parameter_value=1 or $both_error_code=1 or
$both_error_severity=1
)
and
($include_complete_result_pdu_request=1 or
($include_complete_result_pdu_request=0 and
(
($request_pdu=0 or
($request_pdu=1
and
(
contains($vv/PDU, string($pdu_byte_pattern_request))
)
)
)
)
)
)
and
($include_complete_result_parameter_name_request=1 or
($include_complete_result_parameter_name_request=0 and
(
($request_parameter_name=0 or
($request_parameter_name=1
and
(
some $xx in $vv/DtsRequestParameter satisfies
(
contains($xx/ShortName, string($parameter_name_request))
)
)
)
)
)
)
)
and
($include_complete_result_parameter_value_request= 1 or
($include_complete_result_parameter_value_request= 0 and
(
($request_parameter_value=0 or
($request_parameter_value=1
and
(
some $xx in $y/DtsRequestParameter/DtsValue satisfies
(
contains($xx/Value, string($parameter_value_request))
)
)
)
)
)
)
)
and
($include_complete_result_parameter_type_request=1 or
($include_complete_result_parameter_type_request=0 and
(
($request_parameter_type=0 or
($request_parameter_type=1
and
(
some $xx in $vv/DtsRequestParameter/DtsValue satisfies
(
contains($xx/Type, string($parameter_type_request))
)
)
)
)
)
)
)
and
($include_complete_result_error_code_request=1 or
($include_complete_result_error_code_request=0 and
(
($request_error_code=0 or
($request_error_code=1
and
(
some $xx in $vv/DtsRequestParameter/DtsError satisfies
(
contains($xx/CodeDescription, string($error_code_request))
)
)
)
)
)
)
)
and
($include_complete_result_error_severity_request=1 or
($include_complete_result_error_severity_request=0 and
(
($request_error_severity=0 or
($request_error_severity=1
and
(
some $xx in $vv/DtsRequestParameter/DtsError satisfies
(
contains($xx/Severity, string($error_severity_request))
)
)
)
)
)
)
)
and
($include_complete_result_pdu_both=1 or
($include_complete_result_pdu_both=0 and
(
($request_pdu=0 or
($request_pdu=1
and
(
contains($vv/PDU, string($pdu_byte_pattern_both))
)
)
)
)
)
)
and
($include_complete_result_parameter_name_both=1 or
($include_complete_result_parameter_name_both=0 and
(
($request_parameter_name=0 or
($request_parameter_name=1
and
(
some $xx in $vv/DtsRequestParameter satisfies
(
contains($xx/ShortName, string($parameter_name_both))
)
)
)
)
)
)
)
and
($include_complete_result_parameter_value_both=1 or
($include_complete_result_parameter_value_both=0 and
(
($request_parameter_value=0 or
($request_parameter_value=1
and
(
some $xx in $y/DtsRequestParameter/DtsValue satisfies
(
contains($xx/Value, string($parameter_value_both))
)
)
)
)
)
)
)
and
($include_complete_result_parameter_type_both=1 or
($include_complete_result_parameter_type_both=0 and
(
($request_parameter_type=0 or
($request_parameter_type=1
and
(
some $xx in $vv/DtsRequestParameter/DtsValue satisfies
(
contains($xx/Type, string($parameter_type_both))
)
)
)
)
)
)
)
and
($include_complete_result_error_code_both=1 or
($include_complete_result_error_code_both=0 and
(
($request_error_code=0 or
($request_error_code=1
and
(
some $xx in $vv/DtsRequestParameter/DtsError satisfies
(
contains($xx/CodeDescription, string($error_code_both))
)
)
)
)
)
)
)
and
($include_complete_result_error_severity_both=1 or
($include_complete_result_error_severity_both=0 and
(
($request_error_severity=0 or
($request_error_severity=1
and
(
some $xx in $vv/DtsRequestParameter/DtsError satisfies
(
contains($xx/Severity, string($error_severity_both))
)
)
)
)
)
)
)
) (: end all non complete conditions in DtsRequest :)
return $vv
}

{for $vv in $y/DtsResponse
where
(
(: start complete conditions in DtsResponse :)

($include_complete_result_pdu_request=1 and
( ($request_pdu=1
and
(
some $xx in $y/DtsRequest satisfies
(
contains($xx/PDU, string($pdu_byte_pattern_request))
)
)
)
)
)
or
($include_complete_result_parameter_name_request=1 and
( ($request_pdu=1
and
(
some $xx in $y/DtsRequest/DtsRequestParameter satisfies
(
contains($xx/ShortName, string($parameter_name_request))
)
)
)
)
)
or
($include_complete_result_parameter_value_request= 1 and
( ($request_parameter_value=1
and
(
some $xx in $y/DtsRequest/DtsRequestParameter/DtsValue satisfies

(
contains($xx/Value, string($parameter_value_request))
)
)
)
)
)
or
($include_complete_result_parameter_type_request=1 and
( ($request_parameter_type=1
and
(
some $xx in $y/DtsRequest/DtsRequestParameter/DtsValue satisfies

(
contains($xx/Type, string($parameter_type_request))
)
)
)
)
)
or
($include_complete_result_error_code_request=1 and
( ($request_error_code=1
and
(
some $xx in $y/DtsRequest/DtsRequestParameter/DtsError satisfies

(
contains($xx/CodeDescription, string($error_code_request))
)
)
)
)
)
or
($include_complete_result_error_severity_request=1 and
( ($request_error_severity=1
and
(
some $xx in $y/DtsRequest/DtsRequestParameter/DtsError satisfies

(
contains($xx/Severity, string($error_severity_request))
)
)
)
)
)
or
($include_complete_result_pdu_response=1 and
( ($response_pdu=1
and
(
some $xx in $y/DtsResponse satisfies
(
contains($xx/PDU, string($pdu_byte_pattern_response))
)
)
)
)
)
or
($include_complete_result_parameter_name_response= 1 and
( ($response_pdu=1
and
(
some $xx in $y/DtsResponse/DtsReponseParameter satisfies
(
contains($xx/ShortName, string($parameter_name_response))
)
)
)
)
)
or
($include_complete_result_parameter_value_response =1 and
( ($response_parameter_value=1
and
(
some $xx in $y/DtsResponse/DtsResponseParameter/DtsValue
satisfies
(
contains($xx/Value, string($parameter_value_response))
)
)
)
)
)
or
($include_complete_result_parameter_type_response= 1 and
( ($response_parameter_type=1
and
(
some $xx in $y/DtsResponse/DtsResponseParameter/DtsValue
satisfies
(
contains($xx/Type, string($parameter_type_response))
)
)
)
)
)
or
($include_complete_result_error_code_response=1 and
( ($response_error_code=1
and
(
some $xx in $y/DtsResponse/DtsResponseParameter/DtsError
satisfies
(
contains($xx/CodeDescription, string($error_code_response))
)
)
)
)
)
or
($include_complete_result_error_severity_response= 1 and
( ($response_error_severity=1
and
(
some $xx in $y/DtsResponse/DtsResponseParameter/DtsError
satisfies
(
contains($xx/Severity, string($error_severity_response))
)
)
)
)
)
or
($include_complete_result_pdu_both=1 and
( ($both_pdu=1)
and
(
(some $xx in $y/DtsRequest satisfies
(
contains($xx/PDU, string($pdu_byte_pattern_both))
))
and
(some $xx in $y/DtsResponse satisfies
(
contains($xx/PDU, string($pdu_byte_pattern_both))
))
)
)
)
or
($include_complete_result_parameter_name_both=1 and
( ($both_pdu=1)
and
(
(some $xx in $y/DtsRequest/DtsRequestParameter satisfies
(
contains($xx/ShortName, string($parameter_name_both))
))
and
(some $xx in $y/DtsResponse/DtsResponseParameter satisfies
(
contains($xx/ShortName, string($parameter_name_both))
))
)
)
)
or
($include_complete_result_parameter_value_both=1 and
( ($both_parameter_value=1)
and
(
(some $xx in $y/DtsRequest/DtsRequestParameter/DtsValue
satisfies
(
contains($xx/Value, string($parameter_value_both))
))
and
(some $xx in $y/DtsResponse/DtsResponseParameter/DtsValue
satisfies
(
contains($xx/Value, string($parameter_value_both))
))
)
)
)
or
($include_complete_result_parameter_type_both=1 and
( ($both_parameter_type=1)
and
(
(some $xx in $y/DtsRequest/DtsRequestParameter/DtsValue
satisfies
(
contains($xx/Type, string($parameter_type_both))
))
and
(some $xx in $y/DtsResponse/DtsResponseParameter/DtsValue
satisfies
(
contains($xx/Type, string($parameter_type_both))
))
)
)
)

or
($include_complete_result_error_code_both=1 and
( ($both_error_code=1)
and
(
(some $xx in $y/DtsRequest/DtsRequestParameter/DtsError
satisfies
(
contains($xx/CodeDescription, string($error_code_both))
))
and
(some $xx in $y/DtsResponse/DtsResponseParameter/DtsError
satisfies
(
contains($xx/CodeDescription, string($error_code_both))
))
)
)
)
or
($include_complete_result_error_severity_both=1 and
( ($both_error_severity=1)
and
(
(some $xx in $y/DtsRequest/DtsRequestParameter/DtsError
satisfies
(
contains($xx/Severity, string($error_severity_both))
))
and
(some $xx in $y/DtsResponse/DtsResponseParameter/DtsError
satisfies
(
contains($xx/Severity, string($error_severity_both))
))
)
)
)
)(: end complete conditions in DtsResponse :)
or
(
(: start all non complete conditions in DtsResult :)
(
$response_pdu=1 or $response_parameter_name=1 or
$response_parameter_type=1 or
$response_parameter_value=1 or $response_error_code=1 or
$response_error_severity=1
or
$both_pdu=1 or $both_parameter_name=1 or $both_parameter_type=1 or
$both_parameter_value=1 or $both_error_code=1 or
$both_error_severity=1)

and
($include_complete_result_pdu_response=1 or
($include_complete_result_pdu_response=0 and
(
($response_pdu=0 or
($response_pdu=1
and
(
contains($vv/PDU, string($pdu_byte_pattern_response))

)
)
)
)
)
)
and

($include_complete_result_parameter_name_response= 1 or
($include_complete_result_parameter_name_response= 0 and
(
($response_parameter_name=0 or
($response_parameter_name=1
and
(
some $xx in $vv/DtsResponseParameter satisfies
(
contains($xx/ShortName, string($parameter_name_response))
)
)
)
)
)
)
)
and
($include_complete_result_parameter_value_response =1 or
($include_complete_result_parameter_value_response =0 and
(
($response_parameter_value=0 or
($response_parameter_value=1
and
(
some $xx in $y/DtsResponseParameter/DtsValue satisfies
(
contains($xx/Value, string($parameter_value_response))
)
)
)
)
)
)
)

and
($include_complete_result_parameter_type_response= 1 or
($include_complete_result_parameter_type_response= 0 and
(
($response_parameter_type=0 or
($response_parameter_type=1
and
(
some $xx in $vv/DtsResponseParameter/DtsValue satisfies
(
contains($xx/Type, string($parameter_type_response))
)
)
)
)
)
)
)

and
($include_complete_result_error_code_response=1 or
($include_complete_result_error_code_response=0 and
(
($response_error_code=0 or
($response_error_code=1
and
(
some $xx in $vv/DtsResponseParameter/DtsError satisfies
(
contains($xx/CodeDescription, string($error_code_response))
)
)
)
)
)
)
)
and
($include_complete_result_error_severity_response= 1 or
($include_complete_result_error_severity_response= 0 and
(
($response_error_severity=0 or
($response_error_severity=1
and
(
some $xx in $vv/DtsResponseParameter/DtsError satisfies
(
contains($xx/Severity, string($error_severity_response))
)
)
)
)
)
)
)
and
($include_complete_result_pdu_both=1 or
($include_complete_result_pdu_both=0 and
(
($response_pdu=0 or
($response_pdu=1
and
(
contains($vv/PDU, string($pdu_byte_pattern_both))
)
)
)
)
)
)
and

($include_complete_result_parameter_name_both=1 or
($include_complete_result_parameter_name_both=0 and
(
($response_parameter_name=0 or
($response_parameter_name=1
and
(
some $xx in $vv/DtsResponseParameter satisfies
(
contains($xx/ShortName, string($parameter_name_both))
)
)
)
)
)
)
)
and
($include_complete_result_parameter_value_both=1 or
($include_complete_result_parameter_value_both=0 and
(
($response_parameter_value=0 or
($response_parameter_value=1
and
(
some $xx in $y/DtsResponseParameter/DtsValue satisfies
(
contains($xx/Value, string($parameter_value_both))
)
)
)
)
)
)
)

and
($include_complete_result_parameter_type_both=1 or
($include_complete_result_parameter_type_both=0 and
(
($response_parameter_type=0 or
($response_parameter_type=1
and
(
some $xx in $vv/DtsResponseParameter/DtsValue satisfies
(
contains($xx/Type, string($parameter_type_both))
)
)
)
)
)
)
)

and
($include_complete_result_error_code_both=1 or
($include_complete_result_error_code_both=0 and
(
($response_error_code=0 or
($response_error_code=1
and
(
some $xx in $vv/DtsResponseParameter/DtsError satisfies
(
contains($xx/CodeDescription, string($error_code_both))
)
)
)
)
)
)
)
and
($include_complete_result_error_severity_both=1 or
($include_complete_result_error_severity_both=0 and
(
($response_error_severity=0 or
($response_error_severity=1
and
(
some $xx in $vv/DtsResponseParameter/DtsError satisfies
(
contains($xx/Severity, string($error_severity_both))
)
)
)
)
)
)
)
) (: end all non complete conditions in DtsResponse :)
return $vv
}
</DtsResult>
else ()
}
case element (CloseComPrimitive)
return
{
if(
($exclude_items=0 and
($after_comprimitive_logicallink_name=1 or $after_comprimitive_name=1
or
$after_comprimitive_id=1) and

(
( $after_comprimitive_logicallink_name=0 or
($ after_comprimitive_logicallink_name=1 and
(
some $z in $y/LogicalLink satisfies
(
contains($z/ShortName, string($logical_link_name))
)
)
)
)
and
( $after_comprimitive_name=0 or
( $after_comprimitive_name=1 and
(
contains($y/ShortName, string($comprimitive_name))
)
)
)
and
($ after_comprimitive_id=0 or
($ after_comprimitive_id=1 and
(
contains($y/ID, string($comprimitive_id))
)
)
)
)
)) then
return $y
else ()
}

case element(StopTrace)
{
if( $after_startstoptrace=1 and $exclude_items=0) then
return $y
else ()
}

default return $y
}

</Trace> </ProcessValueTrace>


paul.rusu@gmail.com 12-14-2005 09:22 AM

Re: XQuery how to keep order of elements?
 
Hi,

Actually I got the syntax fixed. The typeswitch shouldn't have been
inside { }.

My last issue is: typeswitch ($y) ... case element(a):
.................. $y/CertainChild - is not recognized. Now how is
XQuery supposed to know what type is $y.. How do you do
a cast?

Paul



All times are GMT. The time now is 08:26 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.