Single restxq call, multiple db:replace. Second one always fail, but the error message seems unrelated.
Monday, 16 July 2012 · 3 messages · last reply 18 Jul 2012
FB
France Baril16 Jul 2012 19:04 #
Hi,
I have a process where for each input file, I must create 2 output files. For some reason, I seem to be unable to use more than 1 db:replace in the same function. I have tried pieces of code separately to ensure that every individual piece works. They do work. For your information, I have included my tests as comments after the function.
(: param $lang is the desired target language of the translation :)
declare %rest:path("/admin/convert-to-xliff")
%rest:GET
%rest:query-param("lang", "{$lang}", '')
updating function admin:convert-to-xliff($lang as xs:string){
(: Src language is assumed to always be en-us as per business rules:)
let $src-lang := "en-us"
for $x in app:open-db($src-lang)
let $xliff-stylesheet := app:get-translation-xliff-to-xsl()
let $skeleton-stylesheet := app:get-translation-xliff-skeleton-xsl()
let $params := map {"lang-to" := $lang}
let $target-uri := replace(base-uri($x), $src-lang, $lang)
let $target-skeleton-uri := replace($target-uri, '.xml',
'_xliffskeleton.xml')
let $xliff-doc := xslt:transform($x, $xliff-stylesheet, $params)
let $xliff-skeleton := xslt:transform($x, $skeleton-stylesheet)
return db:replace("Translated-units", $target-uri, document{$
xliff-doc}), db:replace("Translated-units", $target-skeleton-uri, document {
$xliff-skeleton})
};
(: db:replace("Translated-units", $target-uri,
document{$xliff-doc}) --- Creates the expected files in the expected
location :)
(: db:replace("Translated-units", $target-skeleton-uri, document
{$xliff-skeleton}) --- Creates the expected files in the expected location
:)
(: concat($target-uri, ' --- ', $target-skeleton-uri) --- remove
decl as updating function to test this, both paths are set :) - I tested the $target-uri and $target-skeleton-uri as strings, and they both get the expected values as string outputs.
- The db:replace for each of them works individually.
- However, when I try 2 db:replace, the second one return an error: [XPST0008]
Undefined variable $target-skeleton-uri.
- If I reverse the db:replace, the 'new' second one gets the error: [XPST0008]
Undefined variable $target-uri. Therefore, it looks like it has nothing to do with the fact that the variable is undefined.
Any clue?
Thanks,
France Baril
P.S. I'm using BaseX 7.2.1
--
France Baril
Architecte documentaire / Documentation architect
france.baril at architextus.com
(514) 572-0341
MK
M. van Keulen17 Jul 2012 09:03 #
Hi,
Not that I tested or tried it, but it seems to me to be a matter operator priorities, hence of brackets around both db:replace functions: ( db:replace(...) , db:replace(...) ).
Otherwise the XQuery parser will parse it as
updating function ... {
( let ... for ... let ... let ... return db:replace(...) ) ,
db:replace(...)
}Do you see how this makes your $target-skeleton-uri out-of-scope?
Regards,
Maurice van Keulen
Quoted text · France Baril · 63 lines
On 16-07-12 17:04, France Baril wrote: > Hi, > > I have a process where for each input file, I must create 2 output > files. For some reason, I seem to be unable to use more than 1 > db:replace in the same function. I have tried pieces of code > separately to ensure that every individual piece works. They do work. > For your information, I have included my tests as comments after the > function. > > (: param $lang is the desired target language of the translation :) > declare %rest:path("/admin/convert-to-xliff") > %rest:GET > %rest:query-param("lang", "{$lang}", '') > updating function admin:convert-to-xliff($lang as xs:string){ > (: Src language is assumed to always be en-us as per business rules:) > let $src-lang := "en-us" > for $x in app:open-db($src-lang) > let $xliff-stylesheet := app:get-translation-xliff-to-xsl() > let $skeleton-stylesheet := app:get-translation-xliff-skeleton-xsl() > let $params := map {"lang-to" := $lang} > let $target-uri := replace(base-uri($x), $src-lang, $lang) > let $target-skeleton-uri := replace($target-uri, '.xml', > '_xliffskeleton.xml') > let $xliff-doc := xslt:transform($x, $xliff-stylesheet, $params) > let $xliff-skeleton := xslt:transform($x, $skeleton-stylesheet) > return db:replace("Translated-units", $target-uri, > document{$xliff-doc}), db:replace("Translated-units", > $target-skeleton-uri, document {$xliff-skeleton}) > }; > > (: db:replace("Translated-units", $target-uri, > document{$xliff-doc}) --- Creates the expected files in the expected > location :) > (: db:replace("Translated-units", $target-skeleton-uri, > document {$xliff-skeleton}) --- Creates the expected files in the > expected location :) > (: concat($target-uri, ' --- ', $target-skeleton-uri) --- > remove decl as updating function to test this, both paths are set :) > > > * I tested the $target-uri and $target-skeleton-uri as strings, and > they both get the expected values as string outputs. > * The db:replace for each of them works individually. > * However, when I try 2 db:replace, the second one return an error: > [XPST0008] Undefined variable $target-skeleton-uri. > * If I reverse the db:replace, the 'new' second one gets the error: > [XPST0008] Undefined variable $target-uri. Therefore, it looks > like it has nothing to do with the fact that the variable is > undefined. > > Any clue? > > Thanks, > > France Baril > P.S. I'm using BaseX 7.2.1 > > -- > France Baril > Architecte documentaire / Documentation architect > france.baril at architextus.com <mailto:france.baril at architextus.com> > (514) 572-0341
--
---------------------------------------------------------------------- Dr.Ir. M. van Keulen - Associate Professor, Data Management Technology Univ. of Twente, Dept of EEMCS, POBox 217, 7500 AE Enschede, Netherlands Email: m.vankeulen at utwente.nl, Phone: +31 534893688, Fax: +31 534892927 Room: ZI 3039, WWW: http://www.cs.utwente.nl/~keulen
FB
France Baril18 Jul 2012 18:49 #
Hi,
I didn't realize the ',' would take me that far out. I was reading it as 'join' type of punctuation.
This explains that. Everything works as expected now.
Thank you!
On Tue, Jul 17, 2012 at 3:03 AM, M. van Keulen <m.vankeulen at utwente.nl>wrote:
Quoted text · M. van Keulen · 93 lines
> Hi, > > Not that I tested or tried it, but it seems to me to be a matter operator > priorities, hence of brackets around both db:replace functions: ( > db:replace(...) , db:replace(...) ). > Otherwise the XQuery parser will parse it as > > updating function ... { > ( let ... for ... let ... let ... return db:replace(...) ) , > db:replace(...) > } > > Do you see how this makes your $target-skeleton-uri out-of-scope? > > Regards, > Maurice van Keulen > > > On 16-07-12 17:04, France Baril wrote: > > Hi, > > I have a process where for each input file, I must create 2 output > files. For some reason, I seem to be unable to use more than 1 db:replace > in the same function. I have tried pieces of code separately to ensure that > every individual piece works. They do work. For your information, I have > included my tests as comments after the function. > > (: param $lang is the desired target language of the translation :) > declare %rest:path("/admin/convert-to-xliff") > %rest:GET > %rest:query-param("lang", "{$lang}", '') > updating function admin:convert-to-xliff($lang as xs:string){ > (: Src language is assumed to always be en-us as per business rules:) > let $src-lang := "en-us" > for $x in app:open-db($src-lang) > let $xliff-stylesheet := app:get-translation-xliff-to-xsl() > let $skeleton-stylesheet := app:get-translation-xliff-skeleton-xsl > () > let $params := map {"lang-to" := $lang} > let $target-uri := replace(base-uri($x), $src-lang, $lang) > let $target-skeleton-uri := replace($target-uri, '.xml', > '_xliffskeleton.xml') > let $xliff-doc := xslt:transform($x, $xliff-stylesheet, $params) > let $xliff-skeleton := xslt:transform($x, $skeleton-stylesheet) > return db:replace("Translated-units", $target-uri, document{$ > xliff-doc}), db:replace("Translated-units", $target-skeleton-uri, document{ > $xliff-skeleton}) > }; > > (: db:replace("Translated-units", $target-uri, > document{$xliff-doc}) --- Creates the expected files in the expected > location :) > (: db:replace("Translated-units", $target-skeleton-uri, document > {$xliff-skeleton}) --- Creates the expected files in the expected location > :) > (: concat($target-uri, ' --- ', $target-skeleton-uri) --- remove > decl as updating function to test this, both paths are set :) > > > - I tested the $target-uri and $target-skeleton-uri as strings, and > they both get the expected values as string outputs. > - The db:replace for each of them works individually. > - However, when I try 2 db:replace, the second one return an error: [XPST0008] > Undefined variable $target-skeleton-uri. > - If I reverse the db:replace, the 'new' second one gets the error: [XPST0008] > Undefined variable $target-uri. Therefore, it looks like it has > nothing to do with the fact that the variable is undefined. > > Any clue? > > Thanks, > > France Baril > P.S. I'm using BaseX 7.2.1 > > -- > France Baril > Architecte documentaire / Documentation architect > france.baril at architextus.com > (514) 572-0341 > > > -- > ---------------------------------------------------------------------- > Dr.Ir. M. van Keulen - Associate Professor, Data Management Technology > Univ. of Twente, Dept of EEMCS, POBox 217, 7500 AE Enschede, Netherlands > Email: m.vankeulen at utwente.nl, Phone: +31 534893688, Fax: +31 534892927 > Room: ZI 3039, WWW: http://www.cs.utwente.nl/~keulen > > > >
--
France Baril
Architecte documentaire / Documentation architect
france.baril at architextus.com
(514) 572-0341
Written for BaseX 7.3. BaseX may have changed since: please check the current documentation.
⚡Generated with XQuery