Source port with default fallback value? - xproc

I have an XProc step where I would like the input source to work like this:
if a URL is provided on the command line using -isource=foo.xml, then the document at that URL is used as the source document;
if no URL is provided, then the document default.xml should be used.
Is it possible to obtain this behaviour in XProc?

As suggested by Florent on the XProc mailing list, using a p:document inside the p:input works just fine as a default. Specifying something else from outside simply overrides it:
<p:declare-step version="1.0" xmlns:p="http://www.w3.org/ns/xproc"
name="main">
<p:input port="source">
<p:document href="default.xml"/>
</p:input>
<p:output port="result"/>
<p:identity/>
</p:declare-step>
Run it with:
calabash test.xpl
and:
calabash --input source=myinput.xml test.xpl
to see the difference..
HTH!

Related

XPROC p:file-mkdir not found

I'm using XPROC and the XPROC Processor MorganaXProc-IIIse. I'm actually just trying to create a directory through XPROC. However, all I get is this error message:
No visible declaration for '{http://www.w3.org/ns/xproc-step/filesystem}file-mkdir' found: Check spelling, imports or #use-when values.
Code:
<?xml version="1.0" encoding="UTF-8"?>
<p:declare-step xmlns:p="http://www.w3.org/ns/xproc" xmlns:pf="http://www.w3.org/ns/xproc-step/filesystem" name="pipeline" version="3.0">
<p:variable name="base.dir" select="'.'"/>
<pf:file-mkdir href="${basedir}/lib"/>
</p:declare-step>
Since documentation is very limited, any hint is appreciated.
Thanks
In the context of XProc 3, the file-mkdir step is in the namespace http://www.w3.org/ns/xproc so using the prefix p your pipeline declares for that should work: <p:file-mkdir href="${basedir}/lib"/> instead of <pf:file-mkdir href="${basedir}/lib"/>.

Why does my query report "Steps within a path expression must yield nodes"?

I'm relatively new to XQuery and I'm using a XML with the following format (MODSXML):
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<modsCollection xmlns="http://www.loc.gov/mods/v3"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.loc.gov/mods/v3
http://www.loc.gov/standards/mods/v3/mods-3-0.xsd">
<mods ID="ISI:000330282600027" version="3.0">
<titleInfo>
<title>{Minimum Relative Entropy for Quantum Estimation: Feasibility and General
Solution}</title>
</titleInfo>
I'm trying to retrieva all titles of the articles contained on the XML file. The expression I'm using is the following:
for $x in collection("ExemploBibtex")/"quantuminformation.xml"/modsCollection/mods/titleInfo/title
return <title>$x/text()</title>
When I try to run this expression on Base, I get the following error:
"[XPTY0019] Steps within a path expression must yield nodes; xs:string
found."
Can anybody tell me what's wrong? The result I was expecting was a list with all the titles in the document.
Okay, problem solved in the BaseX Mailing List :D
I needed to declare the namespace. So now I'm using:
declare namespace v3 ="http://www.loc.gov/mods/v3";
for $doc in collection('ExemploBibtex')
where matches(document-uri($doc), 'quantuminformation.xml')
return $doc/v3:modsCollection/v3:mods/v3:titleInfo/v3:title/text()
And it works.
The problem is here:
collection("ExemploBibtex")/"quantuminformation.xml"/modsCollection
This returns a string with content quantuminformation.xml for each file/root node in the ExemploBibtex collection, and then tries to perform an axis step on each of these strings -- which is not allowed.
It seems you want to access to document quantuminformation.xml within the collection ExemploBibtex. To open a specific file of a collection, use following syntax instead:
collection("ExemploBibtex/quantuminformation.xml")/modsCollection
I cut of the last axis steps for readability and keeping the code lines short; simply add them again, they're fine.

Use REST in R, httpPUT method

I am implementing an application on R and now I'm trying to use REST protocol to communicate with an external application interface. It allows the app because this interaction has indicated in its documentation. I'm using a library called RCurl. Specifically I am using the function httpPUT. I have no idea about I'm doing wrong, but there is no change in the parameter that I want to modify it. My function is:
httpput_power<-function(DF_DEVICE_IDE_value){
require(XML)
require(RCurl)
power<-""
host<-"http://localhost:3171/devices/"
id_devices<-DF_DEVICE_IDE_value[1,1]
reader<-"/reader/parameter/RF_READ_POWER"
half_url<-paste(host,id_devices,"")
full_url<-paste(half_url,reader,"")
url_reader<-gsub(" ","", full_url , fixed=TRUE)
request="14.5"
httpPUT(url_reader, request)
}
Does anyone know a library for REST in R?. I not sure if RCurl is the most suited to do this task.
then there is an example in the documentation for the application to do a PUT with REST:
PUT http://host_address:3161/devices/{device-id}/reader/parameter/
{PARAM_NAME}
The value of the parameter.
Example: 30.5
Example:
<result>
<class>
com.keonn.impl.protocol.DefaultISO18000_6CParameters$Filter
</class>
<noFilter>false</noFilter>
<active>false</active>
<truncate>UNSPECIFIED</truncate>
<mask>
<bank>EPC</bank>
<pointer>32</pointer>
<maskLength>2</maskLength>
<mask>FF00</mask>
</mask>
</result>
I'm sure the URL is generated correctly, and in my case the parameter is RF_READ_POWER

XPROC - Generation of files in secondary port

My requirement is to generate one XML file and few HTML files in the secondary port. I have configured few steps in XProc.
Here’s the sample code:
<p:xslt name="create-document">
<p:input port="stylesheet">
<p:document href="stylesheet.xsl" />
</p:input>
</p:xslt>
<p:for-each>
<p:iteration-source>
<p:pipe step="create-document" port="secondary" />
</p:iteration-source>
<p:store>
<p:with-option name="doctype-public" select="'-//W3C//DTD XHTML 1.0 Frameset//EN'" />
<p:with-option name="doctype-system" select="'http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd'" />
<p:with-option name="encoding" select="'UTF-8'" />
<p:with-option name="media-type" select="'text/html'" />
<p:with-option name="method" select="'xhtml'" />
<p:with-option name="omit-xml-declaration" select="'no'" />
</p:store>
</p:for-each>
The problem here is HTML file is generated properly. And the XML file is generated, but I am not able to view the XML content. Instead it displays everything in HTML format.This is because of <p:store> in the above code snippet.
How do you have two <p:store> steps? (One for HTML and the other for XML)
It would be nice if you could somehow determine with which xsl:result-document parameters each document on the secondary output was written. You would be able to duplicate those for your p:store. But you can derive other things from each document. You can retrieve the document name using base-uri(), and you can look at for instance the root element. You can put these values in a variable using:
<p:variable name="path" select="base-uri(/*)"/>
<p:variable name="root" select="local-name(/*)"/>
(Put these just below the p:iteration-source.)
You then need to decide how to call p:store. You could use XPath if, provided your XProc parser supports XPath 2.0 (like XMLCalabash does). But I’d recommend using a p:choose like this:
<p:choose>
<p:when test="ends-with($path, '.xhtml')">
<p:store
doctype-public="-//W3C//DTD XHTML 1.0 Frameset//EN"
doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd"
encoding="UTF-8"
media-type="text/html"
method="xhtml"
omit-xml-declaration="no">
<p:with-option name="href" select="$path"/>
</p:store>
</p:when>
<p:otherwise>
<p:store
encoding="UTF-8"
media-type="application/xml"
method="xml"
omit-xml-declaration="no">
<p:with-option name="href" select="$path"/>
</p:store>
</p:otherwise>
</p:choose>
(This entire p:choose replaces the p:store you already have.)
The test in p:when only looks at $path, but you could include a test for $root as well, if you like.
It also requires you to use .xhtml as extension in your xsl:result-document statements for the HTML output, but you can easily tweak that if you like.
The var and the choose should be enough to get your XML written properly, at least.
Good luck!

XForms bind element error

I am changing my code to use binds in XForms (which is better practice than using nodesets everywhere!) but I am getting errors.
The error message I receive is: "Error: XForms Error (8): id (data_criterion) does not refer to a bind element..."
From tutorials/guides I have been using, it seems as though this should work, but clearly I am missing something! (btw, I was modeling my binding code after the examples here: http://en.wikibooks.org/wiki/XForms/Bind)
I originally thought the problem was due to the fact I was using xf:select controls as opposed to xf:input like the examples, but even once I dumbed down my code to the most simplistic code, I still receive errors!
This is the model code I am using:
<xf:model id="select_data">
<xf:instance id="criteria_data" xmlns="">
<file>
<criteria>
<criterion></criterion>
</criteria>
</file>
</xf:instance>
<bind id="data_criterion" nodeset="instance('criteria_data')/criteria/criterion"/>
</xf:model>
As for the ui code, this is what I have:
<xf:input bind="data_criterion">
<xf:label>Enter criteria:</xf:label>
</xf:input>
The error message I receive is: "Error: XForms Error (8): id (data_criterion) does not refer to a bind element..."
Anyone have any insight to what the problem is? Also, is there any special usage of bindings and xf:select (with xf:itemset) controls that I should be aware of? (I am ultimately using a lot of xf:select controls on my form..)
Thanks in advance!
EDIT:
I ran the code through this validator, and I got this message (refers to the bind line):
"Warning: Should the following element have the XForms namespace applied?: bind (line 66)"
A couple of things you might want to change:
Not sure of this is the reason for the error, but the nodeset expression should be instance('criteria_data')/criteria/..., without file. Remember: instance() returns the root element, not the document node. (This one you took care by updating the question; good)
You are missing the xf on the bind. It should be: <xf:bind id="data_criterion" nodeset="instance('criteria_data')/criteria/criterion"/>.
See below a full example with your code, which works fine for me under Orbeon Forms:
<xhtml:html xmlns:xhtml="http://www.w3.org/1999/xhtml"
xmlns:xforms="http://www.w3.org/2002/xforms"
xmlns:xf="http://www.w3.org/2002/xforms"
xmlns:xxforms="http://orbeon.org/oxf/xml/xforms"
xmlns:ev="http://www.w3.org/2001/xml-events"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:fr="http://orbeon.org/oxf/xml/form-runner">
<xhtml:head>
<xhtml:title>SO Bind</xhtml:title>
<xf:model id="select_data">
<xf:instance id="criteria_data" xmlns="">
<file>
<criteria>
<criterion>Gaga</criterion>
</criteria>
</file>
</xf:instance>
<xf:bind id="data_criterion" nodeset="instance('criteria_data')/criteria/criterion"/>
</xf:model>
</xhtml:head>
<xhtml:body>
<xf:input bind="data_criterion">
<xf:label>Enter criteria:</xf:label>
</xf:input>
</xhtml:body>
</xhtml:html>

Resources