Re: [Xsltforms-support] xforms context function
Brought to you by:
alain-couthures
From: Christopher D. <cd...@vi...> - 2010-02-02 21:59:45
|
Alain, Here is the test case for the xforms context function. The sample allows a user to edit the title and author of a book. The data is copied to a separate instance for editing and then, if the user decides to save the changes, the original values in the first instance should be replaced with the modified values from the second instance. Let me know if I can help further. Chris <?xml version="1.0" ?> <?xml-stylesheet href="xsltforms.xsl" type="text/xsl"?> <html xmlns="http://www.w3.org/1999/xhtml" xmlns:xf="http://www.w3.org/2002/xforms" xmlns:ev="http://www.w3.org/2001/xml-events" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <head> <xf:model> <!-- DATA FROM EXTERNAL SOURCES --> <xf:instance id="library"> <library> <books> <book> <title>The Astonishing Life of Octavian Nothing, Traitor to the Nation, Volume II: The Kingdom on the Waves</title> <author>M. T. Anderson</author> </book> <book> <title>The Way We Work</title> <author>David Macaulay with Richard Walker, illustrated by David Macaulay</author> </book> <book> <title>Old Bear</title> <author>Kevin Henkes</author> </book> </books> </library> </xf:instance> <xf:instance id="editbook"> <book> <title></title> <author></author> </book> </xf:instance> </xf:model> <title>context() Test</title> <style> td { border: 1px solid #000000; } </style> </head> <body> <xf:group ref="instance('editbook')"> <xf:switch> <xf:case id="noedit" selected="true"/> <xf:case id="edit"> <div style="width: 100%; height: 100%; position: absolute; background-color: #fff;"> <table> <tr> <td> Title </td> <td> <xf:input ref="title"/> </td> </tr> <tr> <td> Author </td> <td> <xf:input ref="author"/> </td> </tr> <tr> <td colspan="2"> <xf:trigger> <xf:label> Cancel </xf:label> <xf:action ev:event="DOMActivate"> <xf:setvalue ref="title" value="''"/> <xf:setvalue ref="author" value="''"/> <xf:toggle case="noedit" /> </xf:action> </xf:trigger> <xf:trigger> <xf:label> Save </xf:label> <xf:action ev:event="DOMActivate"> <xf:setvalue ref="instance('library')/books/book[index('books')]/title" value="context()/title"/> <xf:setvalue ref="instance('library')/books/book[index('books')]/author" value="context()/author"/> <xf:toggle case="noedit" /> </xf:action> </xf:trigger> </td> </tr> </table> </div> </xf:case> </xf:switch> </xf:group> <xf:group ref="instance('library')"> <table> <thead> <tr> <td></td> <td> <b>Title</b> </td> <td> <b>Author</b> </td> </tr> </thead> <tbody> <xf:repeat id="books" nodeset="books/book"> <td> <xf:trigger> <xf:label> Edit </xf:label> <xf:action ev:event="DOMActivate"> <xf:setvalue ref="instance('editbook')/title" value="context()/title"/> <xf:setvalue ref="instance('editbook')/author" value="context()/author"/> <xf:toggle case="edit" /> </xf:action> </xf:trigger> </td> <td> <xf:output ref="title"/> </td> <td> <xf:output ref="author"/> </td> </xf:repeat> </tbody> </table> </xf:group> </body> </html> -----Original Message----- From: COUTHURES Alain [mailto:ala...@ag...] Sent: Tuesday, February 02, 2010 3:21 PM To: Christopher Dedels Cc: xsl...@li... Subject: Re: [Xsltforms-support] xforms context function Christopher, > It appears that the context function does not work correctly. Here is sample code to reproduce the issue: > > <xf:repeat id="books" nodeset="instance('library')/books/book"> > <xf:trigger appearance="minimal"> > <xf:label> > <xf:output ref="title"/> > </xf:label> > <xf:setvalue ref="instance('customer')/book/title" value="context()/title" ev:event="DOMActivate"/> > </xf:trigger> > </xf:repeat> > > It appears that the context function is returning a reference to the instance('customer')/book/title node, not the instance('library')/books[index('books')]/book node as expected. > Can you please provide a full test case ? It would surely accelerate debugging. Thanks! -Alain |