Page 1 of 1

Passing directory parameter to Xquery from Trans Scenario

Posted: Tue Oct 29, 2013 6:33 pm
by wolandscat
Oxygen 15 / Windows 7

I have an Xquery that starts with the statement:
for $file in collection("../test_set_001/?select=*.xml");

this finds all the XML files in the directory test_set_001 and runs the remaining statements on them.

What I really want is to be able to set up different Transform scenarios which reference different test set directories.

So I set up a parameter {test_set} and give it value 'test_set_001'

Now I want to replace the above 'collection' statement with one that takes the parameter e.g. something like

for $file in collection (concat ('../', ${test_set}, '?select=*.xml'));

This won't compile. If I put ${test_set} in quotes it doesn't get replaced. This should be simple I guess, but it's not clear from the documentation how substitution works...

any help appreciated.

- thomas

Re: Passing directory parameter to Xquery from Trans Scenari

Posted: Wed Oct 30, 2013 1:07 pm
by adrian
Hi,

Declare test_set as an external variable:

Code: Select all

declare variable $test_set as xs:string external;
Then use it as any other variable:

Code: Select all

for $file in collection (concat ('../', $test_set, '?select=*.xml'))
You can specify the value of test_set when editing the transformation scenario configuration (press the Parameters button).

Regards,
Adrian

Re: Passing directory parameter to Xquery from Trans Scenari

Posted: Wed Oct 30, 2013 6:36 pm
by wolandscat
Hi,

thanks for the answer. I have added the declaration to the xquery.

In the transformation scenario, I added a variable 'test_set' and a value for it. (It's not clear whether it should be 'test_set', '{test_set}', '$test_set', '${test_set}' or something else).

When I run the scenario, I get the error:
....
Engine name: Saxon-PE XQuery 9.5.0.2
Severity: error
Description: XPDY0002: No value supplied for required parameter $test_set
Start location: 2:0
URL: http://www.w3.org/TR/xpath20/#ERRXPDY0002


However, the query does appear to actually work. I set up another transformation scenario, with a different parameter value. It also generates the same error, but then appears to work.

What should I make of this?

- thomas

Re: Passing directory parameter to Xquery from Trans Scenari

Posted: Thu Oct 31, 2013 8:47 pm
by adrian
wolandscat wrote:In the transformation scenario, I added a variable 'test_set' and a value for it. (It's not clear whether it should be 'test_set', '{test_set}', '$test_set', '${test_set}' or something else).
If you have declared the variable as external in XQuery, Oxygen should have already presented its name when you pressed the Parameters button (when configuring the scenario). So you shouldn't have to manually enter its name, it should already be in the list of parameters. It's just the plain name BTW: test_set.

Regards,
Adrian

Re: Passing directory parameter to Xquery from Trans Scenari

Posted: Fri Nov 01, 2013 4:26 pm
by wolandscat
Yes, I discovered that does happen, and seems to work when you follow the Oxygen proper workflow. It wasn't that obvious initially, because there is a lot on the screen in Oxygen. I'm still not completely sure I understand how Oxygen 'knows' when there really is a binding between a given Xquery and its one or more transformation scenarios. But executing them does now seem to work as I would expect.

thanks for the input.

- thomas