Revision [1795]
Last edited on 2011-11-23 06:51:45 by DavidLeeAdditions:
Note that in prior versions of xmlsh which used Saxon 9.2 or before, predeclaring the xmlsh namespace was required. This is no longer necessary (or works).
An interesting use of eval is to call xslt from within xquery or visa-versa. The context is passed to eval as the stdin and the output of the command becomes the result value of the expression. These examples are in xquery either via the <[ ]> syntax or the [[CommandXquery xquery]] command and require calling xquery from xmlsh to activate the extension function.
An interesting use of eval is to call xslt from within xquery or visa-versa. The context is passed to eval as the stdin and the output of the command becomes the result value of the expression. These examples are in xquery either via the <[ ]> syntax or the [[CommandXquery xquery]] command and require calling xquery from xmlsh to activate the extension function.
Deletions:
An interesting use of eval is to call xslt from within xquery. The context is passed to eval as the stdin and the output of the command becomes the result value of the expression. These examples are in xquery either via the <[ ]> syntax or the [[CommandXquery xquery]] command and require calling xquery from xmlsh to activate the extension function.
Revision [1791]
Edited on 2011-11-14 10:59:18 by DavidLeeAdditions:
The namespace "xmlsh" is **predeclared** for the XML expression syntax <[ ... ]> as well as the [[CommandXQuery xquery]] command.
Similary the syntax to xquery is supported
xquery -n -q 'xmls:eval("echo hi")'
Similary the syntax to xquery is supported
xquery -n -q 'xmls:eval("echo hi")'
Deletions:
The java class to import is ""org.xmlsh.xpath.XPathFunctions""
This can be done in the shell, or within an xslt or xquery script itself by using "declare namespace"
Example
This namespace is **predeclared** for the XML expression syntax <[ ... ]>.
Revision [732]
Edited on 2009-09-10 04:32:11 by DavidLeeAdditions:
An interesting use of eval is to call xslt from within xquery. The context is passed to eval as the stdin and the output of the command becomes the result value of the expression. These examples are in xquery either via the <[ ]> syntax or the [[CommandXquery xquery]] command and require calling xquery from xmlsh to activate the extension function.
Deletions:
Revision [731]
Edited on 2009-09-10 04:31:03 by DavidLeeAdditions:
An alternative of the above which can use variables for the stylesheet
let $style := "style.xsl"
return
/foo/bar/xmlsh:eval("xslt" , ("-f" , $style) )/spam
An alternative which passes the input context as a third argument
let $style := "style.xsl"
return
xmlsh:eval("xslt" , ("-f" , $style), /foo/bar )/spam
let $style := "style.xsl"
return
/foo/bar/xmlsh:eval("xslt" , ("-f" , $style) )/spam
An alternative which passes the input context as a third argument
let $style := "style.xsl"
return
xmlsh:eval("xslt" , ("-f" , $style), /foo/bar )/spam
Revision [730]
Edited on 2009-09-10 04:29:23 by DavidLeeAdditions:
===Calling XSLT from XQuery. ===
An interesting use of eval is to call xslt from within xquery. The context is passed to eval as the stdin and the output of the command becomes the result value of the expression.
Example, in an XQuery expression, or file run from xmlsh
/foo/bar/xmlsh:eval("xslt -f style.xsl")/spam
calls "xslt" with the sytlesheet "style.xsl" passing the input context from /foo/bar as the input and then the output is further evaluated to extract the /spam child
An interesting use of eval is to call xslt from within xquery. The context is passed to eval as the stdin and the output of the command becomes the result value of the expression.
Example, in an XQuery expression, or file run from xmlsh
/foo/bar/xmlsh:eval("xslt -f style.xsl")/spam
calls "xslt" with the sytlesheet "style.xsl" passing the input context from /foo/bar as the input and then the output is further evaluated to extract the /spam child
Revision [709]
Edited on 2009-09-04 14:11:48 by DavidLeeAdditions:
The java class to import is ""org.xmlsh.xpath.XPathFunctions""
Deletions:
Revision [708]
Edited on 2009-09-04 14:11:02 by DavidLeeAdditions:
This namespace is **predeclared** for the XML expression syntax <[ ... ]>.
For example, the following works without using an explicit declaration
echo <[ /xmlsh:eval("xcat") ]>
In order to use the extension functions within the [[CommandXPath xpath]], [[CommandXQuery xquery]] or [[CommandXslt xslt]] commands it must be declared either within xmlsh or for the case of xquery and xslt within their code/stylesheets.
For example, the following works without using an explicit declaration
echo <[
In order to use the extension functions within the [[CommandXPath xpath]], [[CommandXQuery xquery]] or [[CommandXslt xslt]] commands it must be declared either within xmlsh or for the case of xquery and xslt within their code/stylesheets.
Revision [695]
Edited on 2009-08-27 11:04:12 by DavidLeeAdditions:
===eval===
The **eval** xpath function evaluates its first argument as an xmlsh string (identical to the [[CommandEval eval]] command) and optionally its second argument as positional parameters. The return value of the eval function is the standard output of the command.
Examples
xecho <[ xmlsh:eval("xecho $*" , ("foo" , , 1 ) ) ]>
xquery -n 'xmlsh:eval("xls")'
xpath -n 'xmlsh:eval("xls $*" , "*.xml")'
var=<[ xmlsh:eval("xls") ]>
The **eval** xpath function evaluates its first argument as an xmlsh string (identical to the [[CommandEval eval]] command) and optionally its second argument as positional parameters. The return value of the eval function is the standard output of the command.
Examples
xecho <[ xmlsh:eval("xecho $*" , ("foo" ,
xquery -n 'xmlsh:eval("xls")'
xpath -n 'xmlsh:eval("xls $*" , "*.xml")'
var=<[ xmlsh:eval("xls") ]>