Hello Isidro,
According to XForms Specifications, "response-body" has to return the root
element not the document node so your proposed fix is correct:
".documentElement" will be added in XSLTForms next build.
Thanks!
-Alain
> Le 17 janvier 2014 à 00:16, Isidro Vila Verde <[email protected]> a écrit :
>
> Hello members,
>
> I have a situation where I would like to copy/clone the response-body to a
> instance, so I wrote this code.
>
> <xf:instance id="customer"> <!-- instance to submit -->
> <r xmlns="">
> <name/>
> <email/>
> </r>
> </xf:instance>
>
> <xf:instance xmlns="" id="messages"> <!-- instance to hold the error
> messages -->
> <messages>
> <xforms-submit-error>
> <error-type/>
> <response-body/>
> </xforms-submit-error>
> </messages>
> </xf:instance>
>
> <xf:action ev:event="xforms-submit-error">
> <xf:setvalue
> ref="instance('messages')/xforms-submit-error/error-type"
> value="event('error-type')"/>
> <xf:insert
> context="instance('messages')/xforms-submit-error/response-body"
> nodeset="dummy"
> origin="event('response-body')"/>
> </xf:action>
>
> However, when the instance customer is submitted and the server answer with a
> HTTP error message 403 and this content
>
> <error module="/home/jvv/basex/webapp/saveCustomer.xqm" code="err:XUTY0013"
> value="" line="70" column="9">
> <desc>Source expression in copy clause must return a single node.</desc>
> </error>
>
> the instance "instance('messages')/xforms-submit-error/error-type" is updated
> correctly with value 'resource-error' but the instance
> "instance('messages')/xforms-submit-error/response-body" remains unchanged.
>
> After a lot a tries I decided to follow the xsltforms.js with the debugger
> and found that it fails in function XsltForms_insert.prototype.run. It fails
> when try to insert the clone node with DOM method appendChild (or
> insertBefore, it depends on target)
>
> XsltForms_insert.prototype.run = function(element, ctx) {
> ...
> } else {
> var nodeAfter;
> if (index >= nodes.length && nodes.length !== 0) {
> nodeAfter = nodes[nodes.length - 1].nextSibling;
> } else {
> nodeAfter = nodes[index];
> }
> if (nodeAfter) {
> nodeAfter.parentNode.insertBefore(clone, nodeAfter);
> } else {
> parent.appendChild(clone);
> }
> var repeat = nodes.length > 0?
> XsltForms_browser.getMeta(nodes[0], "repeat") : null;
> nodes.push(clone);
> if (repeat) {
>
>
> document.getElementById(repeat).xfElement.insertNode(clone,
> nodeAfter);
> }
> }
> ...
>
> After inspect the parent and clone I found the clone is a DocumentNode and
> not a Element or Attribute node and though that should be the reason to fail.
>
>
> As I needed to overcome this, I did some more debug and found this line in
> xsltforms.js
>
> evcontext["response-body"] =
> [XsltForms_browser.createXMLDocument(req.responseText)];
>
> in function XsltForms_submission.requesteventlog. So I changed it to
>
> evcontext["response-body"] =
> [XsltForms_browser.createXMLDocument(req.responseText).documentElement];
>
> and now it works as I expected, however I don't now if I found a bug in
> XSLTFORMS or if I am using the xforms insert in a wrong way.
>
> I though it could be my mistake trying to insert a DocumentNode into a
> element Node. So I did try first to change the xpath expression in input's
> origin attribute as this
>
> <xf:insert
> context="instance('messages')/xforms-submit-error/response-body"
> nodeset="dummy"
> origin="event('response-body')/*"/>
>
> but it gave a Xsltforms exception
>
>
>
> XSLTForms Exception
> --------------------------
> Error evaluating the following XPath expression :
> event('response-body')/*
> TypeError
> node.selectSingleNode(...) is null
>
>
>
> Another idea I had was try to set the target as an instance root, so I did
> this
>
> <xf:insert
> nodeset="instance('messages')"
> origin="event('response-body')"/>
>
> But it just wiped the entire instance.
>
> So my problem now is: can I assume this is a xsltforms and fix it as I did
> above or am I using the xforms insert element in the wrong way.
>
> Here is my complete xforms example
>
> <?xml-stylesheet type="text/xsl" href="./xsltforms/xsltforms.xsl"?>
> <html
> xmlns="http://www.w3.org/1999/xhtml" <http://www.w3.org/1999/xhtml>
> xmlns:saf="urn:OECD:StandardAuditFile-Tax:PT_1.03_01"
> xmlns:xs="http://www.w3.org/2001/XMLSchema"
> <http://www.w3.org/2001/XMLSchema>
> xmlns:ev="http://www.w3.org/2001/xml-events"
> <http://www.w3.org/2001/xml-events>
> xmlns:xf="http://www.w3.org/2002/xforms" <http://www.w3.org/2002/xforms>
> xmlns:sxf="http://serprest.pt/xpath-functions"
> <http://serprest.pt/xpath-functions>
> sxf:bogus="Workaround for FF's
> bug:<https://bugzilla.mozilla.org/show_bug.cgi?id=94270> ">
> <head>
> <title>Edit customer</title>
> <link type="text/css" rel="stylesheet" href="/static/style.css"/>
> <xf:model>
> <xf:instance id="customer">
> <r xmlns="">
> <name/>
> <email/>
> </r>
> </xf:instance>
> <xf:instance xmlns="" id="messages">
> <messages>
> <xforms-submit-error>
> <error-type/>
> <response-body/>
> </xforms-submit-error>
> </messages>
> </xf:instance>
>
> <xf:submission id="saveCustomer"
> resource="/saveCustomer"
> method="put"
> ref="instance('customer')"
> replace="instance"
> instance="customer"/>
>
> <xf:submission id="showErrors"
> resource="/sendMessagesErrors"
> method="put"
> ref="instance('messages')"
> replace="none"/>
>
> <xf:action ev:event="xforms-submit-error">
> <xf:setvalue
> ref="instance('messages')/xforms-submit-error/error-type"
> value="event('error-type')"/>
> <xf:insert
> context="instance('messages')/xforms-submit-error/response-body"
> nodeset="dummy"
> origin="event('response-body')"/>
> </xf:action>
> </xf:model>
> </head>
>
> <body>
> <div id="body">
> <div class="actions">
> <xf:submit submission="saveCustomer">
> <xf:label>Ok</xf:label>
> </xf:submit>
> <xf:submit submission="showErrors">
> <xf:label>ShowErrors</xf:label>
> </xf:submit>
> </div>
> <xf:group ref="instance('customer')" class="customerEdit">
> <xf:input ref="name"/>
> <xf:input ref="email"/>
> </xf:group>
> </div>
> </body>
> </html>
>
> (The submission showErrors is just used to send messages instance out o
> browser and see them with firebug in network panel.)
>
> Thanks in advance for your help
>
>
>
>
>
>
------------------------------------------------------------------------------
CenturyLink Cloud: The Leader in Enterprise Cloud Services.
Learn Why More Businesses Are Choosing CenturyLink Cloud For
Critical Workloads, Development Environments & Everything In Between.
Get a Quote or Start a Free Trial Today.
http://pubads.g.doubleclick.net/gampad/clk?id=119420431&iu=/4140/ostg.clktrk
_______________________________________________
Xsltforms-support mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/xsltforms-support