Hi everyone,
Simple question.. If I have the following instance: <root> <parent> <child> <name>Emmanuel</name <age>6</age> </child> <child> <name>Mustapha</name> <age>5</age> </child> </parent> <grand-parent> <parent/> </grand-parent> </root> I want to copy parent/child elements to grand-parent/parent/ element when user clicks on a button trigger. The best I figure out is the following code: <xforms:group ref="instance('control-instance')/button-trigger"> <xforms:action ev:event="DOMActivate"> <xforms:insert nodeset="instance('main-instance')/grand-parent/parent/child" at="1" position="before"/> <xforms:setvalue ref="instance('main-instance')/grand-parent/parent/child/name" value="instance('main-instance')/parent/*/name"/> </xforms:action> <xforms:trigger appearance="xxforms:image"> <xforms:label>Add children</xforms:label> <xxforms:img src="/images/add.gif"/> </xforms:trigger> </xforms:group> The setvalue is working for the 1st child, and an empty element is inserted too. What I need though is to insert as much elements (2 in this example) as there is child elements. It seems I can't use the xforms:repeat tag to repeat the multiple insert (unless I'm wrong?) so what is the best practice? Is there a simple XPath expression I can use to copy multiple elements through the xforms:insert tag? Thanks for your time.. Jimmy -- 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 ObjectWeb mailing lists service home page: http://www.objectweb.org/wws |
Administrator
|
Jimmy Royer wrote:
> Simple question.. If I have the following instance: > > <root> > <parent> > <child> > <name>Emmanuel</name > <age>6</age> > </child> > <child> > <name>Mustapha</name> > <age>5</age> > </child> > </parent> > <grand-parent> > <parent/> > </grand-parent> > </root> > > I want to copy parent/child elements to grand-parent/parent/ element > when user clicks on > a button trigger. The best I figure out is the following code: > > <xforms:group ref="instance('control-instance')/button-trigger"> > <xforms:action ev:event="DOMActivate"> > <xforms:insert nodeset="instance('main-instance')/grand-parent/parent/child" > at="1" position="before"/> > <xforms:setvalue ref="instance('main-instance')/grand-parent/parent/child/name" > value="instance('main-instance')/parent/*/name"/> > </xforms:action> > <xforms:trigger appearance="xxforms:image"> > <xforms:label>Add children</xforms:label> > <xxforms:img src="/images/add.gif"/> > </xforms:trigger> > </xforms:group> > > The setvalue is working for the 1st child, and an empty element is > inserted too. What I need though is > to insert as much elements (2 in this example) as there is child > elements. It seems I can't use the xforms:repeat > tag to repeat the multiple insert (unless I'm wrong?) so what is the > best practice? > Is there a simple XPath expression I can use to copy multiple elements > through the xforms:insert tag? That's right, xforms:insert only inserts a single node. You can't use xforms:repeat in an action. What you need is XForms 1.1's @while attribute on actions, see: http://www.w3.org/TR/xforms11/#iterated-actions However, this is not yet supported in OPS (but we do want to implement it sooner rather than later). Note that you can now use the XForms 1.1 @origin attribute to copy nodes with xforms:insert, e.g.: <xforms:insert nodeset="instance('main-instance')/grand-parent/parent/child" at="1" position="before" origin="instance('main-instance')/parent/child"[1]/> But this still copies only one node. If you need to copy the entire <parent> element from under <root> to under <grand-parent>, then you can get by copying a single node. Otherwise, I fear that we'll have to either find a dirty hack, or you can implement the moving in XSLT on the server: create a submission with replace="instance", and create a simple service in OPS that performs the XSLT transformation. This may be the cleanest solution at the moment. -Erik -- Technology, music, and more http://erik.bruchez.name/roller/page/ebruchez/ -- 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 ObjectWeb mailing lists service home page: http://www.objectweb.org/wws |
Erik Bruchez wrote:
> Jimmy Royer wrote: > > > Simple question.. If I have the following instance: > > > > <root> > > <parent> > > <child> > > <name>Emmanuel</name > > <age>6</age> > > </child> > > <child> > > <name>Mustapha</name> > > <age>5</age> > > </child> > > </parent> > > <grand-parent> > > <parent/> > > </grand-parent> > > </root> > > > > I want to copy parent/child elements to grand-parent/parent/ element > > when user clicks on > > a button trigger. The best I figure out is the following code: > > > > <xforms:group > ref="instance('control-instance')/button-trigger"> > > <xforms:action ev:event="DOMActivate"> > > <xforms:insert > nodeset="instance('main-instance')/grand-parent/parent/child" > > at="1" position="before"/> > > <xforms:setvalue > ref="instance('main-instance')/grand-parent/parent/child/name" > > value="instance('main-instance')/parent/*/name"/> > > </xforms:action> > > <xforms:trigger appearance="xxforms:image"> > > <xforms:label>Add children</xforms:label> > > <xxforms:img src="/images/add.gif"/> > > </xforms:trigger> > > </xforms:group> > > > > The setvalue is working for the 1st child, and an empty element is > > inserted too. What I need though is > > to insert as much elements (2 in this example) as there is child > > elements. It seems I can't use the xforms:repeat > > tag to repeat the multiple insert (unless I'm wrong?) so what is the > > best practice? > > Is there a simple XPath expression I can use to copy multiple elements > > through the xforms:insert tag? > > That's right, xforms:insert only inserts a single node. > > You can't use xforms:repeat in an action. What you need is XForms > 1.1's @while attribute on actions, see: > > http://www.w3.org/TR/xforms11/#iterated-actions > > However, this is not yet supported in OPS (but we do want to implement > it sooner rather than later). > > Note that you can now use the XForms 1.1 @origin attribute to copy > nodes with xforms:insert, e.g.: > > <xforms:insert > nodeset="instance('main-instance')/grand-parent/parent/child" > at="1" position="before" > origin="instance('main-instance')/parent/child"[1]/> > > But this still copies only one node. > > If you need to copy the entire <parent> element from under <root> to > under <grand-parent>, then you can get by copying a single node. > > Otherwise, I fear that we'll have to either find a dirty hack, or you > can implement the moving in XSLT on the server: create a submission > with replace="instance", and create a simple service in OPS that > performs the XSLT transformation. This may be the cleanest solution at > the moment. First thank you for taking your valuable time, I'm impressed on how Alessandro and you are helpful. The submission solution is indeed the cleanest solution until the @while attribute is implemented. Unfortunately I have a XML Schema attached to my model and it seems I can't submit any instance (I tried a dummy one with necessary information) unless all data in the form is valid, and the trigger button that will copy the node into another will happen before the user complete the form. Is there any way to submit an instance and override xsd validation? Regards, Jimmy -- 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 ObjectWeb mailing lists service home page: http://www.objectweb.org/wws |
Administrator
|
Jimmy Royer wrote:
> The submission solution is indeed the cleanest solution until the @while > attribute is implemented. > Unfortunately I have a XML Schema attached to my model and it seems I > can't submit any > instance (I tried a dummy one with necessary information) unless all > data in the form is valid, > and the trigger button that will copy the node into another will happen > before the user complete > the form. Is there any way to submit an instance and override xsd > validation? attribute on your submission: validate="false" http://www.orbeon.com/ops/doc/reference-xforms-ng#validate-relevant-attributes http://www.w3.org/TR/2004/WD-xforms11-20041115/#submit-attribs -Erik -- Orbeon - XForms Everywhere: http://www.orbeon.com/blog/ -- 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 ObjectWeb mailing lists service home page: http://www.objectweb.org/wws |
Erik Bruchez wrote:
> Jimmy Royer wrote: > >> The submission solution is indeed the cleanest solution until the >> @while attribute is implemented. >> Unfortunately I have a XML Schema attached to my model and it seems I >> can't submit any >> instance (I tried a dummy one with necessary information) unless all >> data in the form is valid, >> and the trigger button that will copy the node into another will >> happen before the user complete >> the form. Is there any way to submit an instance and override xsd >> validation? > > Yes, at least if you are using a nightly build: use the following > attribute on your submission: > > validate="false" > > http://www.orbeon.com/ops/doc/reference-xforms-ng#validate-relevant-attributes > > http://www.w3.org/TR/2004/WD-xforms11-20041115/#submit-attribs Just one thing, with the latest version, I got an alert icon beside each of my xforms:output tags. It looks like the XML schema is validating the instance I am using for the message resources. The schema has the targetNamespace attribute defined and pointing to the right namespace, so I don't understand why it would validate the message instance! I am trying to find out what's wrong looking at the DMV forms example as it is working correctly.. Regards, Jimmy -- 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 ObjectWeb mailing lists service home page: http://www.objectweb.org/wws |
Hi All,
I've run into a situation where I need relative XPath expressions to work in nodeset and relevant expressions, but I've run into 2 problems. 1. I can't get the relevant expression to use a relative path when the nodeset refers to an attribute set. See the bare-bones sample form below. Uncomment the bind expression and the Remove buttons disappear, even though I want them to appear when there's more than one B element. 2. I can't get the delete action to work properly when the trigger is bound to an attribute and the nodeset refers to the parent element list. See sample form below. With problem 2, I can work around it by using an absolute path as I have done below in the sample form. With problem 1, I don't know how to work around it or if I'm doing something wrong. The intention of the bind expression is to hide the Remove button when there's only one B element left. Note that I need to use the ui:removable attribute because I want some B elements to be non-removable. Please help. I really need to get this working. Larry T. Chen Software Engineer Intelenet Communications --------------------------------------------------------- <html xmlns:xf="http://www.w3.org/2002/xforms" xmlns:ev="http://www.w3.org/2001/xml-events" xmlns ="http://www.w3.org/1999/xhtml" xmlns:ui="http://www.example.com/ui" > <head> <title>Nested Repeat Test</title> <xf:model> <xf:instance> <Root xmlns=""> <A name="A1"> <B name="B1"/> <B name="B2"/> </A> <A name="A2"> <B name="B1" ui:removable="true"/> <B name="B2" ui:removable="true"/> </A> </Root> </xf:instance> <!-- Problem 1: This bind declaration intended to hide the Remove buttons when there's only one B element--> <!-- <xf:bind nodeset="//B/@ui:removable" relevant="count(../B) > 1" /> --> </xf:model> </head> <body> <xf:repeat nodeset="A" id="A_index"> <xf:output value="@name"/> <br/> <xf:repeat nodeset="B" id="B_index"> ---<xf:output value="@name"/> <xf:trigger ref="@ui:removable"> <xf:label>Remove</xf:label> <xf:action ev:event="DOMActivate"> <xf:delete nodeset="/Root/A[index('A_index')]/B" at="index('B_index')"/> <!-- Problem 2: Does not work with this <xf:delete nodeset="../B" at="index('B_index')"/> --> </xf:action> </xf:trigger> <br/> </xf:repeat> <br/> </xf:repeat> </body> </html> -- 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 ObjectWeb mailing lists service home page: http://www.objectweb.org/wws |
Administrator
|
Larry,
Same mistake in both cases ;-) 1. <xf:bind nodeset="//B/@ui:removable" relevant="count(../../B) > 1" /> 2. <xf:delete nodeset="../../B" at="index('B_index')"/> When the context is on "@ui:removable", ".." represents the parent "B" element, and "../B" doesn't match to anything. -Erik Larry T. Chen wrote: > Hi All, > > I've run into a situation where I need relative XPath expressions to > work in nodeset and relevant expressions, but I've run into 2 problems. > > 1. I can't get the relevant expression to use a relative path when the > nodeset refers to an attribute set. See the bare-bones sample form > below. Uncomment the bind expression and the Remove buttons disappear, > even though I want them to appear when there's more than one B element. > > 2. I can't get the delete action to work properly when the trigger is > bound to an attribute and the nodeset refers to the parent element > list. See sample form below. > > With problem 2, I can work around it by using an absolute path as I have > done below in the sample form. > With problem 1, I don't know how to work around it or if I'm doing > something wrong. The intention of the bind expression is to hide the > Remove button when there's only one B element left. > Note that I need to use the ui:removable attribute because I want some B > elements to be non-removable. > > Please help. I really need to get this working. > > Larry T. Chen > Software Engineer > Intelenet Communications > > --------------------------------------------------------- > <html > xmlns:xf="http://www.w3.org/2002/xforms" > xmlns:ev="http://www.w3.org/2001/xml-events" > xmlns ="http://www.w3.org/1999/xhtml" > xmlns:ui="http://www.example.com/ui" > > > > <head> > <title>Nested Repeat Test</title> > <xf:model> > <xf:instance> > <Root xmlns=""> > <A name="A1"> > <B name="B1"/> > <B name="B2"/> > </A> <A name="A2"> > <B name="B1" ui:removable="true"/> > <B name="B2" ui:removable="true"/> > </A> </Root> > </xf:instance> > <!-- Problem 1: This bind declaration intended to hide the Remove > buttons when there's only one B element--> > <!-- > <xf:bind nodeset="//B/@ui:removable" relevant="count(../B) > > 1" /> > --> > </xf:model> > </head> > <body> > <xf:repeat nodeset="A" id="A_index"> > <xf:output value="@name"/> > <br/> > <xf:repeat nodeset="B" id="B_index"> > ---<xf:output value="@name"/> > <xf:trigger ref="@ui:removable"> > <xf:label>Remove</xf:label> > <xf:action ev:event="DOMActivate"> > > <xf:delete nodeset="/Root/A[index('A_index')]/B" at="index('B_index')"/> > <!-- Problem 2: Does not work with this > <xf:delete nodeset="../B" > at="index('B_index')"/> > --> > </xf:action> > </xf:trigger> > <br/> > </xf:repeat> > <br/> > </xf:repeat> > </body> > </html> > > > > > > > ------------------------------------------------------------------------ > > > -- > 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 > ObjectWeb mailing lists service home page: http://www.objectweb.org/wws -- Orbeon - XForms Everywhere: http://www.orbeon.com/blog/ -- 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 ObjectWeb mailing lists service home page: http://www.objectweb.org/wws |
Thanks for clearing that up. I kept thinking that when binding to an
attribute, the context node is still the element containing the
attribute, forgetting the fact that in XPath an attribute is considered
a child node of the element. Hopefully this will help others avoid the
same mistake I made.
Larry Erik Bruchez wrote: Larry, -- 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 ObjectWeb mailing lists service home page: http://www.objectweb.org/wws |
Administrator
|
Larry,
> Thanks for clearing that up. I kept thinking that when binding to > an attribute, the context node is still the element containing the > attribute, forgetting the fact that in XPath an attribute is > considered a child node of the element. Your statement above is in fact incorrect: attributes are not children of elements. As per XPath 1.0 [1]: "Each element node has an associated set of attribute nodes; the element is the parent of each of these attribute nodes; however, an attribute node is not a child of its parent element." Also, according to the XML infoset [2], for an element, the [children] property is a list that: "contains element, processing instruction, unexpanded entity reference, character, and comment information items" The [attributes] property is separate. Granted, it is funny in XPath 1.0 that the child / parent relationship works this way. In the XML infoset spec, however, attributes correctly have an [owner element] property instead of a [parent] property, which makes more sense. Phew ;-) But I guess we're stuck with the concept of parent for attributes in XPath. -Erik [1] http://www.w3.org/TR/xpath [2] http://www.w3.org/TR/xml-infoset/#infoitem.element -- Orbeon - XForms Everywhere: http://www.orbeon.com/blog/ -- 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 ObjectWeb mailing lists service home page: http://www.objectweb.org/wws |
Administrator
|
In reply to this post by Jimmy Royer
> With the latest CVS build It works like a charm! thanks again Erik.
> > Just one thing, with the latest version, I got an alert icon beside each > of my xforms:output tags. > It looks like the XML schema is validating the instance I am using for > the message resources. > The schema has the targetNamespace attribute defined and pointing to the > right namespace, so I don't > understand why it would validate the message instance! > > I am trying to find out what's wrong looking at the DMV forms example as > it is working correctly.. Good question! We can't rule out bugs with schema validation, as this has been an unclear part of the XForms spec until recently. In the meanwhile, we should improve styling of xforms:output relative to the alert. We have a bug to track this: http://forge.objectweb.org/tracker/index.php?func=detail&aid=305318&group_id=168&atid=350207 -Erik -- Orbeon - XForms Everywhere: http://www.orbeon.com/blog/ -- 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 ObjectWeb mailing lists service home page: http://www.objectweb.org/wws |
> Just one thing, with the latest version, I got an alert icon beside each
> > of my xforms:output tags. > > It looks like the XML schema is validating the instance I am using for > > the message resources. > > The schema has the targetNamespace attribute defined and pointing to > the > > right namespace, so I don't > > understand why it would validate the message instance! > > > > I am trying to find out what's wrong looking at the DMV forms > example as > > it is working correctly.. > > Good question! We can't rule out bugs with schema validation, as this > has been an unclear part of the XForms spec until recently. In the > meanwhile, we should improve styling of xforms:output relative to the > alert. We have a bug to track this: > > http://forge.objectweb.org/tracker/index.php?func=detail&aid=305318&group_id=168&atid=350207 > I did exactly as in the DMV forms example, i.e. I did a separate schema for the form and another one for the instance. Then imported the instance schema into the form schema: <xs:schema xmlns:foo="http://www.foo.ca/research/compliance/animal-protocol" xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified"> <xs:import namespace="http://www.foo.ca/research/compliance/animal-protocol" schemaLocation="../schema/animal-protocol.xsd"/> <!-- Define type for main-instance --> <xs:complexType name="animal-protocol"> <xs:sequence> <xs:element ref="foo:animal-protocol"/> </xs:sequence> </xs:complexType> <!-- Define type for control-instance --> <xs:element name="control"> <xs:complexType> <xs:sequence> <xs:any namespace="##targetNamespace" processContents="lax" minOccurs="0" maxOccurs="unbounded"/> </xs:sequence> </xs:complexType> </xs:element> </xs:schema> It was working fine with only one schema in the available 3.0.1 release (with the targetNamespace schema tag) but with the CVS version it is not. After some testing, if I comment the control xs:element, the alerts on the ouputs are coming back (which are referring to my messages instance). If I keep the control xs:element but put the processContents to "strict" the alerts does not show (I thought that maybe the lax processing could be the reason alerts weren't showing for some weird reason). If I comment the control xs:element for the DMV forms everything's fine.. so I don't know, its a strange behaviour that I may be the cause in the end. In every case it works now. :-) Good day and thanks for all, Jimmy -- 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 ObjectWeb mailing lists service home page: http://www.objectweb.org/wws |
Free forum by Nabble | Edit this page |