How about –rns option or something like that which would accept a prefix=URI pair as the next argument. Later, this prefix could be used in XPath expressions within the command line. A param=value pair that accepts XPath expressions should probably be marked accordingly with something (say “~”). The character of choice would be of no importance.

 

Example:

Transform  -rns h=http://www.w3.org/1999/xhtml  -in test.xml test.xsl   ~exampleParameter=//h:code

 

In the worse case, you could use a special prefix (say “!”) for option that is actually a prefix=URI pair. Something like:

Transform  !h=http://www.w3.org/1999/xhtml  -in test.xml test.xsl   ~exampleParameter=//h:code

 

And/Or in the worst case, just allow {} to be used as namespace resolvers within the expression. Makes for quite a verbose expression, but it would work in edge cases:

Transform  -in test.xml test.xsl   ~exampleParameter=//{http://www.w3.org/1999/xhtml}code

Wasn’t that one actually path of XPath 1.0’s syntax or am I on the wrong track?

 

From: saxon-help-bounces@lists.sourceforge.net [mailto:saxon-help-bounces@lists.sourceforge.net] On Behalf Of Michael Kay
Sent: Thursday, July 26, 2007 11:05 AM
To: 'Mailing list for SAXON XSLT queries'
Subject: Re: [saxon] how to set a global variable on the command line

 

It is possible to pass in a document node using the syntax

 

+in=input.xml

 

It isn't possible to pass in an element node. You will have to declare the external variable to expect a document node, and then do the selection of the element node within the query.

 

Another alternative of course is to pass the filename in as a string, and fetch the document from within the query.

 

I know that there are XSLT and XQuery products that allow parameter values to be set using an XPath expression, but Saxon doesn't. I've never worked out a sensible way that would allow the namespace context to be set for evaluating such expressions, and without that the facility seems fairly useless.

 

Michael Kay

 


From: saxon-help-bounces@lists.sourceforge.net [mailto:saxon-help-bounces@lists.sourceforge.net] On Behalf Of nathaniel.p.reed@accenture.com
Sent: 26 July 2007 00:31
To: saxon-help@lists.sourceforge.net
Subject: [saxon] how to set a global variable on the command line

I have an XQuery that I want to run on the command-line.  It is in the form of a function call with the argument set to a global variable:

 

declare function myfunc($in as element(inType)) as element(outType)  {….}

declare variable $in as element(inType) external;

myfunc($in)

 

In order to run this XQuery, the variable $in has to be set.  It should be set to the root node in the input XML file, but I haven’t been able to figure out the right syntax to do this.

 

I am able to set global variables to untyped values, like:

 

java –cp saxon.jar net.sf.saxon.Query transform.xq param=value

 

But how do I pass in a document node for “param”?  I have tried using {doc(‘in.xml’}/in} (where in.xml is the input file, and in is the root node), but this expression gets passed in as a string.

 

What’s the right way to do this?  Is it even possible on the command-line?

 

Thanks,

Nate

 

This message is for the designated recipient only and may contain privileged, proprietary, or otherwise private information. If you have received it in error, please notify the sender immediately and delete the original. Any other use of the email by you is prohibited.