Problem using with xforms:insert context/origin with at/position

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Problem using with xforms:insert context/origin with at/position

Pascal Heus
In the attached short code, I'm trying to insert an element using the
"origin" and "context" attributes of xforms:insert. This works fine but
the at= and position= attributes seem to be ignored. The insert is
always the first element.
<xforms:insert context="." nodeset="r:Version"
origin="instance('r:Version-template')" at="last()" position="before"/>
I tried at="last()", at="2", etc.
The attached file can be tested in the sandbox. Any suggestion (or
obvious typo?)
thanks
*P

The original instance is:
            <xforms:instance id="instance">    
                <d:DataCollection>
                    <r:Identification>
                        <r:ID>r:ID</r:ID>
                        <r:IdentifyingAgency>MyAgency</r:IdentifyingAgency>
                        <r:Name>r:Name</r:Name>
                    </r:Identification>
                </d:DataCollection>
           </xforms:instance>

I'm need to insert this after r:IdentifyingAgency
            <xforms:instance id="r:Version-template">
                <r:Version>1.?</r:Version>
            </xforms:instance>
:



<!--
       
               
        Author : Pascal Heus ([hidden email])
        Version: 200609
       
    Copyright (C) 2006 Open Data FOundation ([hidden email])
    Copyright (C) 2004 Orbeon, Inc.
 
    This program is free software; you can redistribute it and/or modify it under the terms of the
    GNU Lesser General Public License as published by the Free Software Foundation; either version
    2.1 of the License, or (at your option) any later version.
 
    This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
    without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
    See the GNU Lesser General Public License for more details.
 
    The full text of the license is available at http://www.gnu.org/copyleft/lesser.html
-->
<xhtml:html
    xmlns:ev="http://www.w3.org/2001/xml-events"
    xmlns:f="http://orbeon.org/oxf/xml/formatting"
    xmlns:xhtml="http://www.w3.org/1999/xhtml"
    xmlns:xi="http://www.w3.org/2003/XInclude"
        xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:xforms="http://www.w3.org/2002/xforms"
    xmlns:xxforms="http://orbeon.org/oxf/xml/xforms"

    xmlns:d="ddi:datacollection:0_1"  
    xmlns:r="ddi:reusable:0_1"
    >
    <xhtml:head>
        <xhtml:title>DDI 3.0 Data Collection Module Editor</xhtml:title>
        <xforms:model>
       
            <xforms:instance id="instance">    
                        <d:DataCollection>
                        <r:Identification>
                                                <r:ID>r:ID</r:ID>
                                                <r:IdentifyingAgency>MyAgency</r:IdentifyingAgency>
                                                <r:Name>Name</r:Name>
                                        </r:Identification>
                        </d:DataCollection>
               </xforms:instance>
               
            <xforms:instance id="r:Version-template">
            <r:Version>1.?</r:Version>
            </xforms:instance>
           
                        <xforms:instance id="formatted-instance">
                                <formatted-instance/>
                        </xforms:instance>
                        <xforms:bind nodeset="instance('formatted-instance')" calculate="xxforms:serialize(instance('instance'), 'html')"/>

       </xforms:model>
      <xhtml:style>
      .section-header {
                        background-color: #d0d0f8;
      font-size: 12pt;
      font-weight:bold;
      margin-top:10px;
      padding:2px;
      }
      </xhtml:style>
     
    </xhtml:head>
    <!-- BODY -->
    <xhtml:body>
                <xhtml:div style="font-size:18pt;">DDI 3.0 Sandbox</xhtml:div>

                <xhtml:div class="section-header">Identification</xhtml:div>
                <xhtml:div>
                        <xforms:group ref="/d:DataCollection/r:Identification">
                                <!--  rID  -->
                                <xforms:group id="r:ID-group">
                                        <xforms:input id="r:ID" ref="r:ID">
                                                <xforms:label id="r:ID-label">ID</xforms:label>
                                                <xforms:alert id="r:ID-alert"/>
                                        </xforms:input>
                                        <xhtml:br />
                                </xforms:group>
                               
                                <!-- r:IdentifyingAgency -->
                                <xforms:group id="r:IdentifyingAgency-group">
                                        <xforms:input ref="r:IdentifyingAgency">
                                                <xforms:label id="r:IdentifyingAgency-label">Prename</xforms:label>
                                                <xforms:alert id="r:IdentifyingAgency-alert"/>
                                        </xforms:input>
                                        <xhtml:br />
                                </xforms:group>
                               
                                <!--  r:Version -->
                                <xforms:group id="r:ID-version">
                                        <xforms:input id="r:Version" ref="r:Version">
                                                <xforms:label id="r:Version-label">Version</xforms:label>
                                                <xforms:alert id="r:Version-alert"/>
                                        </xforms:input>
                                        <xforms:group>
                                        <!--
                                        <xforms:insert nodeset="r:Version" at="min((last(),index('r:VesionDate'),index('r:VesionResponsibilty'),index('r:Affiliation'),index('r:VesionReason') ))" position="before"/>
                                        <xforms:insert nodeset="r:Version" origin="instance('Version-template')" at="last()" position="before"/>
                                        -->
                                        <!--  THIS ALWAYS INSERTS AS FIRST ELEMENT INSTEAD OF LAST -->
                                                <xforms:action ev:event="DOMActivate">
                                                    <xforms:insert context="." nodeset="r:Version" origin="instance('r:Version-template')" at="last()" position="before"/>
                                                </xforms:action>
                                                <xforms:trigger appearance="xxforms:image">
                                                    <xxforms:img src="/images/add.gif"/>
                                                    <xforms:label>Add</xforms:label>
                                                </xforms:trigger>
                                                <xforms:trigger appearance="xxforms:link">
                                                    <xforms:label>Add Version</xforms:label>
                                                </xforms:trigger>
    </xforms:group>
                                </xforms:group>
                        </xforms:group>
                </xhtml:div>
               
                <xhtml:div class="section-header">XML Document</xhtml:div>
                <xhtml:div class="view-xml-container">
                        <xforms:output ref="instance('formatted-instance')" />
                </xhtml:div>
               
    </xhtml:body>
</xhtml: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
Reply | Threaded
Open this post in threaded view
|

RE: Problem using with xforms:insert context/origin with at/position

Ryan Puddephatt
Pascal the @at is relevant to the nodeset, selecting a nodeset of r:version
are picking the position last will always return 1 because there are no
r:version elements, if you want it to be the last of all the nodes use

@context="instance('main-instance')/r:Identification"
@nodeset="*"
@at="last()"
@position="after"

This should work

Ryan

Ryan Puddephatt
Software Engineer

Teleflex Group - IT UK
1 Michaelson Square
Livingston
West Lothian
Scotland
EH54 7DP

e> [hidden email]
t> +44(0)1506 407 110
f> +44(0)1506 407 108

 

>-----Original Message-----
>From: Pascal Heus [mailto:[hidden email]]
>Sent: 24 September 2006 17:04
>To: [hidden email]
>Subject: [ops-users] Problem using with xforms:insert
>context/origin with at/position
>
>In the attached short code, I'm trying to insert an element
>using the "origin" and "context" attributes of xforms:insert.
>This works fine but the at= and position= attributes seem to
>be ignored. The insert is always the first element.
><xforms:insert context="." nodeset="r:Version"
>origin="instance('r:Version-template')" at="last()"
>position="before"/> I tried at="last()", at="2", etc.
>The attached file can be tested in the sandbox. Any suggestion
>(or obvious typo?) thanks *P
>
>The original instance is:
>            <xforms:instance id="instance">    
>                <d:DataCollection>
>                    <r:Identification>
>                        <r:ID>r:ID</r:ID>
>                        
><r:IdentifyingAgency>MyAgency</r:IdentifyingAgency>
>                        <r:Name>r:Name</r:Name>
>                    </r:Identification>
>                </d:DataCollection>
>           </xforms:instance>
>
>I'm need to insert this after r:IdentifyingAgency
>            <xforms:instance id="r:Version-template">
>                <r:Version>1.?</r:Version>
>            </xforms:instance>
>:
>
>
>



--
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
Reply | Threaded
Open this post in threaded view
|

Re: Problem using with xforms:insert context/origin with at/position

Pascal Heus
Ryan:
Many thanks for the clarification, it works fine now.
I have one more issue: how can I count the number of elements with a specific name in an @at=""?
In the following code,  the at="min(...)" always inserts after the first elements. The count() should actually return 2 (as it does in the xforms:output before)
*P

                    <!-- the following line returns 2 -->
                    <br/>COUNT=<xforms:output value="count(*[name()='r:ID' or name()='r:IdentifyingAgency'])" />
                    <br/>LAST=<xforms:output value="*/last()" /><br/>
                    <xforms:group>
                        <xforms:action ev:event="DOMActivate">
                            <!-- the following always inserts after 1 -->
                            <xforms:insert context="." nodeset="*" origin="instance('r:Version-template')"
                                at="min(( last(), count(*[name()='r:ID' or name()='r:IdentifyingAgency']) ))"
                                position="after"/>
                        </xforms:action>
                        <xforms:trigger appearance="xxforms:image">
                            <xxforms:img src="/images/add.gif"/>
                            <xforms:label>Add</xforms:label>
                        </xforms:trigger>
                        <xforms:trigger appearance="xxforms:link">
                            <xforms:label>Add Version</xforms:label>
                        </xforms:trigger>
                       </xforms:group>

Ryan Puddephatt wrote:
Pascal the @at is relevant to the nodeset, selecting a nodeset of r:version
are picking the position last will always return 1 because there are no
r:version elements, if you want it to be the last of all the nodes use

@context="instance('main-instance')/r:Identification"
@nodeset="*"
@at="last()"
@position="after"

This should work

Ryan

Ryan Puddephatt
Software Engineer

Teleflex Group - IT UK
1 Michaelson Square
Livingston
West Lothian
Scotland
EH54 7DP

e> [hidden email]
t> +44(0)1506 407 110
f> +44(0)1506 407 108

 

  
-----Original Message-----
From: Pascal Heus [[hidden email]] 
Sent: 24 September 2006 17:04
To: [hidden email]
Subject: [ops-users] Problem using with xforms:insert 
context/origin with at/position

In the attached short code, I'm trying to insert an element 
using the "origin" and "context" attributes of xforms:insert. 
This works fine but the at= and position= attributes seem to 
be ignored. The insert is always the first element.
<xforms:insert context="." nodeset="r:Version"
origin="instance('r:Version-template')" at="last()" 
position="before"/> I tried at="last()", at="2", etc.
The attached file can be tested in the sandbox. Any suggestion 
(or obvious typo?) thanks *P

The original instance is:
           <xforms:instance id="instance">    
               <d:DataCollection>
                   <r:Identification>
                       <r:ID>r:ID</r:ID>
                       
<r:IdentifyingAgency>MyAgency</r:IdentifyingAgency>
                       <r:Name>r:Name</r:Name>
                   </r:Identification>
               </d:DataCollection>
          </xforms:instance>

I'm need to insert this after r:IdentifyingAgency
           <xforms:instance id="r:Version-template">
               <r:Version>1.?</r:Version>
           </xforms:instance>
:



    


  

-- You receive this message as a subscriber of the [hidden email] mailing list. To unsubscribe: [hidden email] For general help: [hidden email] ObjectWeb mailing lists service home page: http://www.objectweb.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
ObjectWeb mailing lists service home page: http://www.objectweb.org/wws
Reply | Threaded
Open this post in threaded view
|

Re: Problem using with xforms:insert context/origin with at/position

Pascal Heus
In reply to this post by Pascal Heus
To answer my own query:-) ...I just need to refer to the parent element in the insert @at...
Replacing  count(*[name()=... with count(../*[name()=... works
This means that with this trick, I can insert an element at the right place in the children list with respect to my XSchema sequence. Been looking for such functionality for a while and this opens the door to improved editing functionalities. Many thanks to the OPS team for bringing in some of the XForms 1.1 support
*P

-------- Original Message --------
Subject: Re: [ops-users] Problem using with xforms:insert context/origin with at/position
Date: Mon, 25 Sep 2006 07:40:57 -0400
From: Pascal Heus [hidden email]
To: [hidden email]
References: [hidden email]


Ryan:
Many thanks for the clarification, it works fine now.
I have one more issue: how can I count the number of elements with a specific name in an @at=""?
In the following code,  the at="min(...)" always inserts after the first elements. The count() should actually return 2 (as it does in the xforms:output before)
*P

                    <!-- the following line returns 2 -->
                    <br/>COUNT=<xforms:output value="count(*[name()='r:ID' or name()='r:IdentifyingAgency'])" />
                    <br/>LAST=<xforms:output value="*/last()" /><br/>
                    <xforms:group>
                        <xforms:action ev:event="DOMActivate">
                            <!-- the following always inserts after 1 -->
                            <xforms:insert context="." nodeset="*" origin="instance('r:Version-template')"
                                at="min(( last(), count(*[name()='r:ID' or name()='r:IdentifyingAgency']) ))"
                                position="after"/>
                        </xforms:action>
                        <xforms:trigger appearance="xxforms:image">
                            <xxforms:img src="/images/add.gif"/>
                            <xforms:label>Add</xforms:label>
                        </xforms:trigger>
                        <xforms:trigger appearance="xxforms:link">
                            <xforms:label>Add Version</xforms:label>
                        </xforms:trigger>
                       </xforms:group>

Ryan Puddephatt wrote:
Pascal the @at is relevant to the nodeset, selecting a nodeset of r:version
are picking the position last will always return 1 because there are no
r:version elements, if you want it to be the last of all the nodes use

@context="instance('main-instance')/r:Identification"
@nodeset="*"
@at="last()"
@position="after"

This should work

Ryan

Ryan Puddephatt
Software Engineer

Teleflex Group - IT UK
1 Michaelson Square
Livingston
West Lothian
Scotland
EH54 7DP

e> [hidden email]
t> +44(0)1506 407 110
f> +44(0)1506 407 108

 

  
-----Original Message-----
From: Pascal Heus [[hidden email]] 
Sent: 24 September 2006 17:04
To: [hidden email]
Subject: [ops-users] Problem using with xforms:insert 
context/origin with at/position

In the attached short code, I'm trying to insert an element 
using the "origin" and "context" attributes of xforms:insert. 
This works fine but the at= and position= attributes seem to 
be ignored. The insert is always the first element.
<xforms:insert context="." nodeset="r:Version"
origin="instance('r:Version-template')" at="last()" 
position="before"/> I tried at="last()", at="2", etc.
The attached file can be tested in the sandbox. Any suggestion 
(or obvious typo?) thanks *P

The original instance is:
           <xforms:instance id="instance">    
               <d:DataCollection>
                   <r:Identification>
                       <r:ID>r:ID</r:ID>
                       
<r:IdentifyingAgency>MyAgency</r:IdentifyingAgency>
                       <r:Name>r:Name</r:Name>
                   </r:Identification>
               </d:DataCollection>
          </xforms:instance>

I'm need to insert this after r:IdentifyingAgency
           <xforms:instance id="r:Version-template">
               <r:Version>1.?</r:Version>
           </xforms:instance>
:



    


  

-- You receive this message as a subscriber of the [hidden email] mailing list. To unsubscribe: [hidden email] For general help: [hidden email] ObjectWeb mailing lists service home page: http://www.objectweb.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
ObjectWeb mailing lists service home page: http://www.objectweb.org/wws