Thread: [Xsltforms-support] setvalue in XForm
Brought to you by:
alain-couthures
From: <mcu...@co...> - 2011-09-30 00:57:09
|
Hello all: I am attempting to create an Xform (using XSLTForms and MarkLogic) where the instance initially contains no data, like this: <xf:model> <xf:instance xmlns="" id="i1"> <table> <row> <column></column> </row> </table> </xf:instance> </xf:model> I would like to set the value of the column element to "default" upon loading the form in a browser but have not been able to do so. My stab at it is the xquery below but it does not work as hoped. Can anyone tell me a correct way to do this? Thanks, Morgan ---------------------------------- xquery version "1.0-ml"; declare namespace xdmp=" http://marklogic.com/xdmp "; let $page := (xdmp:set-response-content-type("application/xml"), <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 "> <head> <xf:model> <xf:instance xmlns="" id="i1"> <table> <row> <column></column> </row> </table> </xf:instance> </xf:model> <xf:action ev:event="xforms-ready"> <xf:action xf:if="string(instance('i1')/row/column) != 'default'"> <xf:setvalue ref="instance('i1')/row/column" value="'default'" /> </xf:action> </xf:action> </head> <body> <h3>Datafield</h3> <xf:group nodeset="/table"> <xf:repeat id="repeat-row" nodeset="row"> <xf:input ref="column"/> </xf:repeat> <xf:trigger> <xf:label>Add Row</xf:label> <xf:action ev:event="DOMActivate" if="index('repeat-row') != (count(row))"> <xf:insert nodeset="row" at="index('repeat-row')" position="after" /> <xf:setvalue ref="row[index('repeat-row')]/column" value="/table/row/column" /> </xf:action> <xf:action ev:event="DOMActivate" if="index('repeat-row') = (count(row))"> <xf:insert nodeset="row[last()]" position="after" at="last()"/> <xf:setvalue ref="row[last()]/column" value="/table/row/column"/> </xf:action> </xf:trigger> </xf:group> </body> </html> ) let $xslt-pi := processing-instruction xml-stylesheet {'type="text/xsl" href="xsltforms/xsltforms.xsl"'} return ($xslt-pi, $page) |
From: Alain C. <ala...@ag...> - 2011-09-30 12:57:07
|
Hello Morgan, This action has to be defined within the model and not after the model declaration. You can also use a single element for this specific action: <xf:setvalue ev:event="xforms-ready" if="string(instance('i1')/row/column) != 'default'" ref="instance('i1')/row/column" value="'default'" /> Please note that I also replaced "@xf:if" by "@if". Thank you for your feedbacks! -Alain Le 30/09/2011 02:57, mcu...@co... a écrit : > Hello all: > > I am attempting to create an Xform (using XSLTForms and MarkLogic) where the instance initially contains no data, like this: > > <xf:model> > <xf:instance xmlns="" id="i1"> > <table> > <row> > <column></column> > </row> > </table> > </xf:instance> > </xf:model> > > I would like to set the value of the column element to "default" upon loading the form in a browser but have not been able to do so. > > My stab at it is the xquery below but it does not work as hoped. Can anyone tell me a correct way to do this? > > Thanks, > Morgan > > ---------------------------------- > xquery version "1.0-ml"; > declare namespace xdmp="http://marklogic.com/xdmp"; > > let $page := > (xdmp:set-response-content-type("application/xml"), > > > <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"> > <head> > <xf:model> > <xf:instance xmlns="" id="i1"> > <table> > <row> > <column></column> > </row> > </table> > </xf:instance> > </xf:model> > > <xf:action ev:event="xforms-ready"> > <xf:action xf:if="string(instance('i1')/row/column) != 'default'"> > <xf:setvalue ref="instance('i1')/row/column" value="'default'" /> > </xf:action> > </xf:action> > > > </head> > <body> > <h3>Datafield</h3> > <xf:group nodeset="/table"> > <xf:repeat id="repeat-row" nodeset="row"> > <xf:input ref="column"/> > </xf:repeat> > > <xf:trigger> > <xf:label>Add Row</xf:label> > <xf:action ev:event="DOMActivate" if="index('repeat-row') != (count(row))"> > <xf:insert nodeset="row" at="index('repeat-row')" position="after" /> > <xf:setvalue ref="row[index('repeat-row')]/column" > value="/table/row/column" /> > </xf:action> > > <xf:action ev:event="DOMActivate" if="index('repeat-row') = (count(row))"> > <xf:insert nodeset="row[last()]" position="after" at="last()"/> > <xf:setvalue ref="row[last()]/column" value="/table/row/column"/> > </xf:action> > > </xf:trigger> > > > </xf:group> > </body> > </html> > > ) > > let $xslt-pi := processing-instruction xml-stylesheet {'type="text/xsl" href="xsltforms/xsltforms.xsl"'} > return ($xslt-pi, $page) > > > ------------------------------------------------------------------------------ > All of the data generated in your IT infrastructure is seriously valuable. > Why? It contains a definitive record of application performance, security > threats, fraudulent activity, and more. Splunk takes this data and makes > sense of it. IT sense. And common sense. > http://p.sf.net/sfu/splunk-d2dcopy2 > > > _______________________________________________ > Xsltforms-support mailing list > Xsl...@li... > https://lists.sourceforge.net/lists/listinfo/xsltforms-support |