|
[XQuery Talk Mailing List Archive Home] [By Date] [By Thread] [By Subject] [By Author] [Recent Entries] [Reply To This Message] more readable format - can let clause help me hereJeni Tennison jeni at jenitennison.comMon Nov 1 10:32:25 PST 2004
Hi pJ,
> I am using VB.net and microsoft.xml.xquery.dll. I want to break this
> long xquery into more readable format. Can someone please suggest me
> what I am doing wrong.
You are setting the value of the $c1 and $c2 (XQuery) variables to
strings, then referring to those variables and expecting the strings
to be dynamically evaluated as expressions. XQuery can't do dynamic
evaluation of strings as expressions.
An alternative would be to set VB variables to strings, and build up
the query from those strings with something like (forgive my lack of
knowledge of VB syntax):
c1 = "(RP02/TypeCode='NW' and RP05/Type='0')"
c2 = "(RP02/LaborCode='G' and RP02/ModCode='LK' and
RP02/PartCode!='SL' and RP02/ModCode!='SL' and RP05/Type='0' )"
query = "let $price:=sum((document(""f1"")//Repair[" & c1 & " or " &
c2 & "]/RP01/DisplayPrice))" & _
"return <Amount>{$price}</Amount>"
If you don't want to do that, the right thing to do in XQuery is to
declare functions that return the results of the two tests. The query
would look something like:
declare function local:c1 ($repair as element(Repair)) as xs:boolean {
$repair/RP02/TypeCode='NW' and $repair/RP05/Type='0'
};
declare function local:c2 ($repair as element(Repair)) as xs:boolean {
$repair/RP02/LaborCode='G' and $repair/RP02/ModCode='LK' and
$repair/RP02/PartCode!='SL' and $repair/RP02/ModCode!='SL' and
$repair/RP05/Type='0'
};
let $price = sum(document("f1")//Repair[local:c1(.) or local:c2(.)]/RP01/DisplayPrice)
return <Amount>{$price}</Amount>
(untested)
Cheers,
Jeni
---
Jeni Tennison
http://www.jenitennison.com/
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|

Cart








