Hi
I am trying to pass a string to my XQuery as a parameter, $input below. It seems that the string is not being interpreted as XML as I get the following message when I run the query from my .Net client:
Stopped at line 14, column 68:
[XPTY0019] Context node required for sglines; xs:string found.
I believe I don't have the syntax of "declare context item as element(sglines) := document {$input/sglines};" quite right, and maybe " for $i in //line"
The XML I am passing in as a parameter is:
<sglines>
<line lineId="41" note="1064"/>
<line lineId="3" note="0"/>
<line lineId="5" note="0"/>
<line lineId="7" note="0"/>
<line lineId="11" note="0"/>
<line lineId="12" note="0"/>
<line lineId="33" note="0"/>
<line lineId="80" note="0"/>
<line lineId="34" note="0"/>
<line lineId="50" note="0"/>
<line lineId="51" note="0"/>
<line lineId="52" note="0"/>
<line lineId="60" note="0"/>
<line lineId="61" note="0"/>
<line lineId="80" note="0"/>
</sglines>
Help would be much appreciated.
Thanks
Best regards
John Morin
declare namespace dp = "http://www.autodata.ltd.uk/namespaces/content-aggregation";
declare namespace ad = "http://autodata.ltd.uk/technical_topic";
(: return a deep copy of the element withouth namespaces :)
declare namespace xf = "http://tempuri.org/vijfhuizen/com/myMessage/";
declare variable $input external;
declare context item as element(sglines) := document {$input/sglines};
declare function xf:strip-namespace($e as element())
as element()
{
element { xs:QName(local-name($e)) }
{
for $child in $e/(@*,node())
return if ($child instance of element()) then xf:strip-namespace($child) else $child
}
};
let $sgline := $input
return
<aggregation>
{
for $i in //line
let $id := $i/@lineId
let $note := $i/@note
let $elm := //dp:aggregation
let $data := $elm/dp:content[@dataLineId=$id and @noteNumber=$note]
return if(fn:empty($data)) then "" else xf:strip-namespace($data)
}
</aggregation>
IMPORTANT NOTICE: This email and any attachments are confidential and are protected by copyright and/or database rights and are intended for the addressee only. If you are not the named recipient, you must not use, disclose, reproduce, copy or distribute the contents of this communication. If you have received this in error, please contact the sender and then delete this email from your system. The integrity of email across the Internet cannot be guaranteed. The sender therefore does not accept liability for any errors or omissions in the contents of this message which arise as a result of email transmission. Although Autodata Limited has taken precautions to ensure no viruses are present in this email or any attachments, the company cannot accept any responsibility for any loss or damage arising from the use of this email or attachments. Autodata Limited, Priors Way, Maidenhead Berkshire, SL6 2HP, England, UK. Registered as a limited company in England, UK. Registration number 1062717. VAT number GB 208 4782 54 000.
Hi John,
Am 24.07.2012 10:02, schrieb John Morin:
I am trying to pass a string to my XQuery as a parameter, $input below. It seems that the string is not being interpreted as XML as I get the following message when I run the query from my .Net client:
Stopped at line 14, column 68: [XPTY0019] Context node required for sglines; xs:string found.
the value you're passing in is bound to `$input` as an `xs:untypedAtomic`, you have to parse it into an XML document with `parse-xml($input)` [1] to access the child nodes.
Hope that helps, cheers, Leo
Hi Leo
Thank you. Can you tell me exactly how this fits into my query please.
Best regards
John
-----Original Message----- From: Leonard Wörteler [mailto:leo@woerteler.de] Sent: 24 July 2012 09:11 To: John Morin Cc: basex-talk@mailman.uni-konstanz.de Subject: Re: [basex-talk] Context node required problem
Hi John,
Am 24.07.2012 10:02, schrieb John Morin:
I am trying to pass a string to my XQuery as a parameter, $input below. It seems that the string is not being interpreted as XML as I get the following message when I run the query from my .Net client:
Stopped at line 14, column 68: [XPTY0019] Context node required for sglines; xs:string found.
the value you're passing in is bound to `$input` as an `xs:untypedAtomic`, you have to parse it into an XML document with `parse-xml($input)` [1] to access the child nodes.
Hope that helps, cheers, Leo
[1] http://www.w3.org/TR/xpath-functions-30/#func-parse-xml
IMPORTANT NOTICE: This email and any attachments are confidential and are protected by copyright and/or database rights and are intended for the addressee only. If you are not the named recipient, you must not use, disclose, reproduce, copy or distribute the contents of this communication. If you have received this in error, please contact the sender and then delete this email from your system. The integrity of email across the Internet cannot be guaranteed. The sender therefore does not accept liability for any errors or omissions in the contents of this message which arise as a result of email transmission. Although Autodata Limited has taken precautions to ensure no viruses are present in this email or any attachments, the company cannot accept any responsibility for any loss or damage arising from the use of this email or attachments. Autodata Limited, Priors Way, Maidenhead Berkshire, SL6 2HP, England, UK. Registered as a limited company in England, UK. Registration number 1062717. VAT number GB 208 4782 54 000.
Hi,
Am 24.07.2012 11:16, schrieb John Morin:
Thank you. Can you tell me exactly how this fits into my query please.
replace the line
declare context item as element(sglines) := document {$input/sglines};
by:
declare context item as element(sglines) := parse-xml($input)/sglines;
HTH, Leo
basex-talk@mailman.uni-konstanz.de