I'm trying to autoincrement an 'id' attribute in an XML instance (just like in MySQL) .
I found some topics here on autoincrementing element values , but those didn't work for me either. So , my instance looks like this : <nabble_embed><xforms:instance id="faculties-instance"> <faculties xmlns=""> <faculty id=""> <name /> </faculty> </faculties> </xforms:instance></nabble_embed> (I'm not sure if the id attribute is represented correctly in the instance , I didn't find any documentation on this) And the code inside xforms:repeat looks like this : <nabble_embed><xforms:repeat nodeset="faculty" id="faculty-repeat"> <tr> <td> <xforms:trigger appearance="minimal"> <xforms:delete ev:event="DOMActivate" context="instance('faculties-instance')" nodeset="faculty" at="index('faculty-repeat')"/> <xforms:label><img src="/apps/xforms-bookcast/images/remove.gif"/></xforms:label> </xforms:trigger> </td> <td class="form-td"> <xforms:input ref="name"> <xforms:label class="faculties-label">Name</xforms:label> <xforms:alert>The faculty name is required</xforms:alert> </xforms:input> <xforms:action ev:event="DOMActivate"> <xforms:setvalue ref="instance('faculties-instance')/faculty[index('faculty-repeat')]/@id" value="index('faculty-repeat)" /> </xforms:action> </td> </tr> </xforms:repeat></nabble_embed> Instead of instance('faculties-instance')/faculty[index('faculty-repeat')]/@id , I also tried using context()/@id , current()/@id - none of them worked. Thanks in advance ! |
Administrator
|
Vlad,
There are more than one ways to determine what that id should be. Here I assume "max(id) + 1". <xforms:setvalue ref="@id" value="max(instance('faculties-instance')/faculty/@id/xs:integer(.)) + 1"/> One question is: when do you want to call this? I would assume upon inserting a new row. BTW you can write your delete this way: <xforms:delete ev:event="DOMActivate" ref="."/> -Erik On Mon, Jun 18, 2012 at 4:32 PM, Vlad <[hidden email]> wrote: > I'm trying to autoincrement an 'id' attribute in an XML instance (just like > in MySQL) . > I found some topics here on autoincrementing element values , but those > didn't work for me either. > > So , my instance looks like this : > > <xforms:instance id="faculties-instance"> > <faculties xmlns=""> > <faculty id=""> > <name /> > </faculty> > </faculties> > </xforms:instance> > > (I'm not sure if the id attribute is represented correctly in the instance , > I didn't find any documentation on this) > > > And the code inside xforms:repeat looks like this : > > <xforms:repeat nodeset="faculty" id="faculty-repeat"> > <tr> > <td> > <xforms:trigger appearance="minimal"> > <xforms:delete ev:event="DOMActivate" > context="instance('faculties-instance')" nodeset="faculty" > at="index('faculty-repeat')"/> > <xforms:label> > /apps/xforms-bookcast/images/remove.gif </xforms:label> > </xforms:trigger> > </td> > <td class="form-td"> > <xforms:input ref="name"> > <xforms:label > class="faculties-label">Name</xforms:label> > <xforms:alert>The faculty name is > required</xforms:alert> > </xforms:input> > <xforms:action ev:event="DOMActivate"> > <xforms:setvalue > ref="instance('faculties-instance')/faculty[index('faculty-repeat')]/@id" > value="index('faculty-repeat)" /> > </xforms:action> > </td> > </tr> > </xforms:repeat> > > Instead of > instance('faculties-instance')/faculty[index('faculty-repeat')]/@id , I also > tried using context()/@id , current()/@id - none of them worked. > > Thanks in advance ! > > -- > View this message in context: http://orbeon-forms-ops-users.24843.n4.nabble.com/autoincrement-xforms-setvalue-inside-xforms-repeat-tp4655287.html > Sent from the Orbeon Forms (ops-users) mailing list archive at Nabble.com. > > > -- > You receive this message as a subscriber of the [hidden email] mailing list. > To unsubscribe: mailto:[hidden email] > For general help: mailto:[hidden email]?subject=help > OW2 mailing lists service home page: http://www.ow2.org/wws > -- You receive this message as a subscriber of the [hidden email] mailing list. To unsubscribe: mailto:[hidden email] For general help: mailto:[hidden email]?subject=help OW2 mailing lists service home page: http://www.ow2.org/wws |
That xforms:repeat piece of code is used for dislaying and also for adding/editing .
So I guess I'll use some conditional structure , like : <nabble_embed><xforms:action if="not(@id)"> <xforms:setvalue ref="@id" value="max(instance('faculties-instance')/faculty/@id/xs:integer(.)) + 1"/> </xforms:action></nabble_embed> For the 'else' branch (when @id value is set) I think that the value is kept without explicitly specifying it . Am I right ? (I cannot test it right now , I'll be back later) |
It still doesn't work , I think that the <xforms:setvalue> is not executed.
The <faculty> elements are saved in eXist with id="0" , the default value that I defined in the instance : <xforms:instance id="faculties-instance"> <faculties xmlns=""> <faculty id="0"> <name /> </faculty> </faculties> </xforms:instance> I declared the attribute in XSD : <xs:attribute name="id" type="xs:integer"/> This is the binding : <xforms:bind nodeset="instance('faculties-instance')/faculty"> <xforms:bind nodeset="@id" required="true()"/> <xforms:bind nodeset="name" required="true()"/> </xforms:bind> And this is faculty-template , which I specify as an "origin" (attribute) when the new element is generated : <xforms:instance id="faculty-template"> <faculty id="0" xmlns=""> <name /> </faculty> </xforms:instance> Maybe I didn't place the <xforms:setvalue> in the right place ? Thanks. |
This post was updated on .
I found the problem , "Note: <xf:repeat> does not work inside <xf:action>" asa specified here : http://en.wikibooks.org/wiki/XForms/Select_All
So my solution is : <xforms:action if="number(instance('faculties-instance')/faculty[1]/@id) < 1"> <xforms:setvalue ref="instance('faculties-instance')/faculty[1]/@id" value="max(instance('faculties-instance')/faculty/@id/xs:integer(.)) + 1" /> </xforms:action> (put this code outside of <xforms:repeat>) (faculty[1] , because the newly-added elements are put first) |
Administrator
|
Vlad,
Good to hear you found the issue. -Erik On Thu, Jun 21, 2012 at 12:39 AM, Vlad <[hidden email]> wrote: > I found the problem , "Note: <xf:repeat> does not work inside <xf:action>" > asa specified here : http://en.wikibooks.org/wiki/XForms/Select_All > http://en.wikibooks.org/wiki/XForms/Select_All > So my solution is : > > /<xforms:action if="number(instance('faculties-instance')/faculty[1]/@id) > < 1"> > <xorms:setvalue ref="instance('faculties-instance')/faculty[1]/@id" > value="max(instance('faculties-instance')/faculty/@id/xs:integer(.)) + 1" /> > </xforms>/ > > (put this code outside of <xforms:repeat>) > > (faculty[1] , because the newly-added elements are put first) > > -- > View this message in context: http://orbeon-forms-ops-users.24843.n4.nabble.com/autoincrement-xforms-setvalue-inside-xforms-repeat-tp4655287p4655323.html > Sent from the Orbeon Forms (ops-users) mailing list archive at Nabble.com. > > > -- > You receive this message as a subscriber of the [hidden email] mailing list. > To unsubscribe: mailto:[hidden email] > For general help: mailto:[hidden email]?subject=help > OW2 mailing lists service home page: http://www.ow2.org/wws > -- You receive this message as a subscriber of the [hidden email] mailing list. To unsubscribe: mailto:[hidden email] For general help: mailto:[hidden email]?subject=help OW2 mailing lists service home page: http://www.ow2.org/wws |
Free forum by Nabble | Edit this page |