sedna - Odd behavior in XQuery comments -
i have set of xquery transformations running on files stored in sedna database. have following format:
declare namespace ns0 = "http://www.someuri.com/foo.xsd"; declare namespace ns1 = "http://www.someuri.com/bar.xsd"; (:declare few functions following:) declare function local:to-xs-boolean( $string xs:string? ) xs:boolean? { if (fn:upper-case($string) = 'y') xs:boolean('true') else if (fn:upper-case($string) = 'n') xs:boolean('false') (:if isn't y or n attempt normal cast - fail if isn't of 'true', 'false', 1, or 0 :) else if ($string != '') xs:boolean($string) else () (:endif:) (:endif:) }; (:omitted several other functions:) (:start main program:) (: { :) $formname in /ns0:formname return <ns1:newformname> { let $address := $formname/ns0:address return <newaddress>{ (:omitted code , elements unrelated question:) }</newaddress> } (:omitted code , elements unrelated question:) </ns1:newformname>
now here question. see line right above 'for' reads '(: { :)'? should comment, reason crucial proper function of query. if delete (or remove '{' inside comment)
sedna message: error xpdy0002 dynamic error if evaluation of expression relies on part of dynamic context has not been assigned value.
if uncomment (so line reads '{') get
sedna message: error xpst0003 static error if expression not valid instance of grammar defined in a.1 ebnf. details: @ (393:1), syntax error, unexpected { @ (798:33), syntax error, unexpected end of file, expecting "," or }
if have both uncommented , add matching '}' end of file get
sedna message: error xpst0003 static error if expression not valid instance of grammar defined in a.1 ebnf. details: @ (393:1), syntax error, unexpected {
if add other text comment (like '(:text foo bar baz() blah {:)') continue work long leave '{' in there.
has ever seen before or have idea might causing it? isn't crucial issue (i can make sure have '(:{:)' in of transformations), making me curious. help, or joining me in puzzlement.
oh 1 other quick note - don't know if makes difference, running query out of java using charles foster's sedna api (http://www.cfoster.net/sedna/)
edit: here different query wrote shows same issue. seems reproducable me, if syntax error related me reproducing syntax error. leave old 1 future viewers of question aren't confused.
declare namespace ns0 = "http://www.someuri.com/initialschema.xsd"; declare namespace ns1 = "http://www.someuri.com/finalschema.xsd"; declare function local:to-address( $recipient xs:string?, $line1 xs:string?, $line2 xs:string?, $line3 xs:string?, $city xs:string?, $provinceorstate xs:string?, $country xs:string?, $postalorzip xs:string? ) element() { if (fn:upper-case($country) = 'ca' or fn:upper-case($country) = 'us') if (fn:upper-case($country) = 'ca') <canadianaddress> <city>{ $city }</city> <country>{ $country }</country> <postalcode>{ $postalorzip }</postalcode> <province>{ $provinceorstate }</province> <recipient>{ fn:normalize-space($recipient) }</recipient> <streetaddress>{ $line1 }</streetaddress> <streetaddress>{ $line2 }</streetaddress> <streetaddress>{ $line3 }</streetaddress> <streetaddress/> </canadianaddress> else <usaddress> <city>{ $city }</city> <country>{ $country }</country> <zipcode>{ $postalorzip }</zipcode> <state>{ $provinceorstate }</state> <recipient>{ fn:normalize-space($recipient) }</recipient> <streetaddress>{ $line1 }</streetaddress> <streetaddress>{ $line2 }</streetaddress> <streetaddress>{ $line3 }</streetaddress> </usaddress> (:endif:) else if ($country != '') <internationaladdress> <city>{ $city }</city> <country>{ $country }</country> <postalcode>{ $postalorzip }</postalcode> <recipient>{ fn:normalize-space($recipient) }</recipient> <streetaddress>{ $line1 }</streetaddress> <streetaddress>{ $line2 }</streetaddress> <streetaddress>{ $line3 }</streetaddress> </internationaladdress> else <canadianaddress> <city>{ $city }</city> <country>{ $country }</country> <postalcode>{ $postalorzip }</postalcode> <province>{ $provinceorstate }</province> <recipient>{ fn:normalize-space($recipient) }</recipient> <streetaddress>{ $line1 }</streetaddress> <streetaddress>{ $line2 }</streetaddress> <streetaddress>{ $line3 }</streetaddress> <streetaddress/> </canadianaddress> (:endif:) (:endif:) }; (:{:) $addressform1 in /ns0:addressform let $token := xs:integer(data($addressform1/ns0:submissionid)) return <ns1:newaddressform> <submissionid>{ data($addressform1/ns0:submissionid) }</submissionid> { let $currentaddress := $addressform1/ns0:currentaddress return <newaddress>{ local:to-address( concat( $addressform1/ns0:fullname/ns0:firstname, ' ', substring(data($addressform1/ns0:fullname/ns0:middlename), 1, 1), ' ', $addressform1/ns0:fullname/ns0:lastname ), data($currentaddress/ns0:line1), data($currentaddress/ns0:line2), data($currentaddress/ns0:line3), data($currentaddress/ns0:city), data($currentaddress/ns0:provinceorstate), data($currentaddress/ns0:country), data($currentaddress/ns0:postalorzipcode) ) }</newaddress> } </ns1:newaddressform>
and here sample data new query
<?xml version="1.0"?> <ns0:addressform xmlns:ns0="http://www.someuri.com/initialschema.xsd"> <ns0:submissionid>23774</ns0:submissionid> <ns0:fullname> <ns0:firstname>first</ns0:firstname> <ns0:middlename>middle</ns0:middlename> <ns0:lastname>last</ns0:lastname> </ns0:fullname> <ns0:currentaddress> <ns0:line1>line 1</ns0:line1> <ns0:line2>line 2</ns0:line2> <ns0:line3>line 3</ns0:line3> <ns0:city>city</ns0:city> <ns0:provinceorstate>province</ns0:provinceorstate> <ns0:postalorzipcode>h0h 0h0</ns0:postalorzipcode> <ns0:country>ca</ns0:country> </ns0:currentaddress> </ns0:addressform>
if syntax error behind kind point out me line on?
the problem following line:
for $formname in /ns0:formname
in sedna (remember sedna database, not xquery processor) there no way define default context item (see xquery 1.0, 2.1.2 dynamic context) prior query execution. doesn't know how evaluate ./ns0:formname
(which equivalent of simple /ns0:formname
) - doesn't know .
means in case.
you should load document want process database , access doc()
function:
for $formname in doc('forms')/ns0:formname
as far know, may try charles fosters's xqj api sedna (which should anyway better xml:db api) has support defining context item.
btw, if have questions concerning sedna's xml:db or xqj it's better ask them directly in sedna-discussion list. there chances charles answer you.
Comments
Post a Comment