Nested Repeats, position()?

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

Nested Repeats, position()?

ChrisSpeare
I have a nested set of repeats, how do you know what position() is related to - the inner out outer repeat?  Can you reference it via the id of the repeat.  So master_id.position()?
Reply | Threaded
Open this post in threaded view
|

Re: Nested Repeats, position()?

fl.schmitt(ops-users)
Hi Chris,

> I have a nested set of repeats, how do you know what position() is related to
> - the inner out outer repeat?  Can you reference it via the id of the
> repeat.  So master_id.position()?

you will encounter problems when using position() regarding repeat
items; googling for "ops-users position()" returns some mailing list
threads concerning that problem. Instead, you could try

<xforms:output value="count(preceding-sibling::*) + 1"/>

to get the position of the current repeat element.

To refer an outer repeat, you can use a OF xforms extension named
xxforms:repeat-current with the id of the referred repeat. See:

http://www.orbeon.com/ops/doc/reference-xforms-2#ops-extensions

so it looks like
                                                                        <xforms:group ref="xxforms:repeat-current('outer')">
        <xforms:output value="count(preceding-sibling::*) + 1"/>
</xforms:group>


HTH
florian




--
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: Nested Repeats, position()?

Ryan Puddephatt
Florian,
    Thats actually not the case any more, the latest OF build makes use of the position() function and has done for a while

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
w> www.teleflex.com

"Measuring programming progress by lines of code is like measuring aircraft building progress by weight." - Bill Gates
"If you lie to the compiler, it will get its revenge." - Henry Spencer
"It's hard enough to find an error in your code when you're looking for it; it's even harder when you've assumed your code is error-free." - Steve McConnell
"If builders built buildings the way programmers wrote programs, then the first woodpecker that came along would destroy civilization." - Gerald Weinberg



Florian Schmitt wrote:
Hi Chris,

I have a nested set of repeats, how do you know what position() is related to
- the inner out outer repeat?  Can you reference it via the id of the
repeat.  So master_id.position()?

you will encounter problems when using position() regarding repeat items; googling for "ops-users position()" returns some mailing list threads concerning that problem. Instead, you could try

<xforms:output value="count(preceding-sibling::*) + 1"/>

to get the position of the current repeat element.

To refer an outer repeat, you can use a OF xforms extension named xxforms:repeat-current with the id of the referred repeat. See:

http://www.orbeon.com/ops/doc/reference-xforms-2#ops-extensions

so it looks like
                                    <xforms:group ref="xxforms:repeat-current('outer')">
    <xforms:output value="count(preceding-sibling::*) + 1"/>
</xforms:group>


HTH
florian



-- 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: Nested Repeats, position()?

fl.schmitt(ops-users)
Ryan,

>     Thats actually not the case any more, the latest OF build makes use
> of the position() function and has done for a while

good to hear, thank you for the hint. But regarding the special case
where an "outer" repeat should be referenced, using position() seems not
to work properly. I've attached an example file where the position() of
both the "actual" and an "outer" repeat is used as xforms:output/@value,
and only in the first case the position is correct. Using
preceding-sibling gives the correct value also in the second case.

florian


--
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

test2.xhtml (2K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Nested Repeats, position()?

Ryan Puddephatt
Florian,
using your <xforms:group> will change the context, and probably the position(), but I wouldn't know for sure without testing

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
w> www.teleflex.com

"Measuring programming progress by lines of code is like measuring aircraft building progress by weight." - Bill Gates
"If you lie to the compiler, it will get its revenge." - Henry Spencer
"It's hard enough to find an error in your code when you're looking for it; it's even harder when you've assumed your code is error-free." - Steve McConnell
"If builders built buildings the way programmers wrote programs, then the first woodpecker that came along would destroy civilization." - Gerald Weinberg



Florian Schmitt wrote:
Ryan,

    Thats actually not the case any more, the latest OF build makes use of the position() function and has done for a while

good to hear, thank you for the hint. But regarding the special case where an "outer" repeat should be referenced, using position() seems not to work properly. I've attached an example file where the position() of both the "actual" and an "outer" repeat is used as xforms:output/@value, and only in the first case the position is correct. Using preceding-sibling gives the correct value also in the second case.

florian

-- 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: Nested Repeats, position()?

Alessandro Vernet
Administrator
In reply to this post by fl.schmitt(ops-users)
Florian,

On 6/5/07, Florian Schmitt <[hidden email]> wrote:
> good to hear, thank you for the hint. But regarding the special case
> where an "outer" repeat should be referenced, using position() seems not
> to work properly. I've attached an example file where the position() of
> both the "actual" and an "outer" repeat is used as xforms:output/@value,
> and only in the first case the position is correct. Using
> preceding-sibling gives the correct value also in the second case.

Thank you for the example. But I think this is the expected behavior.
Expression are evaluated in a context, which is made of 3 things: the
context item, the position, and the context size. When you do:

<xforms:group ref="xxforms:repeat-current('outer')">
    <xforms:output value="count(preceding-sibling::*) + 1"/> -
    <xforms:output value="position()" />
</xforms:group>

The xforms:group sets the context item to the current node for the
outer iteration. But a group always makes the position = 1 and context
size = 1. So if you are inside a nested repeat, you can't use
position() anymore to get the position of the outer repeat. In that
case you will need to use count([preceding-sibling::foo).

Alex
--
Orbeon Forms - Web 2.0 Forms, open-source, for the Enterprise
http://www.orbeon.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
ObjectWeb mailing lists service home page: http://www.objectweb.org/wws
Reply | Threaded
Open this post in threaded view
|

Re: Nested Repeats, position()?

Ryan Puddephatt
Alex,
    Thanks that answers my confusion as well

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
w> www.teleflex.com

"Measuring programming progress by lines of code is like measuring aircraft building progress by weight." - Bill Gates
"If you lie to the compiler, it will get its revenge." - Henry Spencer
"It's hard enough to find an error in your code when you're looking for it; it's even harder when you've assumed your code is error-free." - Steve McConnell
"If builders built buildings the way programmers wrote programs, then the first woodpecker that came along would destroy civilization." - Gerald Weinberg



Alessandro Vernet wrote:
Florian,

On 6/5/07, Florian Schmitt [hidden email] wrote:
good to hear, thank you for the hint. But regarding the special case
where an "outer" repeat should be referenced, using position() seems not
to work properly. I've attached an example file where the position() of
both the "actual" and an "outer" repeat is used as xforms:output/@value,
and only in the first case the position is correct. Using
preceding-sibling gives the correct value also in the second case.

Thank you for the example. But I think this is the expected behavior.
Expression are evaluated in a context, which is made of 3 things: the
context item, the position, and the context size. When you do:

<xforms:group ref="xxforms:repeat-current('outer')">
   <xforms:output value="count(preceding-sibling::*) + 1"/> -
   <xforms:output value="position()" />
</xforms:group>

The xforms:group sets the context item to the current node for the
outer iteration. But a group always makes the position = 1 and context
size = 1. So if you are inside a nested repeat, you can't use
position() anymore to get the position of the outer repeat. In that
case you will need to use count([preceding-sibling::foo).

Alex

-- 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: Nested Repeats, position()?

ChrisSpeare
Ok so back to the question in hand, if I have a nested loop and I want to set the value of a nested element how do I go about it?  Normally I would do:

<xforms:select1 ref="/Country/IdentificationCode" model="model_SeaManifest" >
        <xforms:action ev:event="xforms-value-changed">
                <xforms:setvalue ref="instance('instance_model_SeaManifest')/ManifestInformation/Shipment[position()]/Schedule/RoutingPort/Country/Name" value="instance('CountryList')/item[countryCode=instance('instance_model_SeaManifest')/ManifestInformation/Shipment[position()]/Schedule/RoutingPort/Country/IdentificationCode]/countryName"/>
        </xforms:action>
        ...
</xforms:select1>

Where the repeat was just shipment, however the repeat concerns a repeat on routing port as well.  So how do I set the value of the inner item in the context of a select1 action?
Reply | Threaded
Open this post in threaded view
|

Re: Nested Repeats, position()?

Alessandro Vernet
Administrator
Chris,

On 6/6/07, ChrisSpeare <[hidden email]> wrote:

> <xforms:select1 ref="/Country/IdentificationCode" model="model_SeaManifest"
> >
>         <xforms:action ev:event="xforms-value-changed">
>                 <xforms:setvalue
> ref="instance('instance_model_SeaManifest')/ManifestInformation/Shipment[position()]/Schedule/RoutingPort/Country/Name"
> value="instance('CountryList')/item[countryCode=instance('instance_model_SeaManifest')/ManifestInformation/Shipment[position()]/Schedule/RoutingPort/Country/IdentificationCode]/countryName"/>
>         </xforms:action>
>         ...
> </xforms:select1>
>
> Where the repeat was just shipment, however the repeat concerns a repeat on
> routing port as well.  So how do I set the value of the inner item in the
> context of a select1 action?
You are repeating on the Shipment element. I would use
xxforms:repeat-current() here. It is an extension, but it makes
expressions much simpler to understand. The value expression would
become:

instance('CountryList')/item[countryCode=xxforms:repeat-current()/Schedule/RoutingPort/Country/IdentificationCode]/countryName

Alex
--
Orbeon Forms - Web 2.0 Forms, open-source, for the Enterprise
http://www.orbeon.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
ObjectWeb mailing lists service home page: http://www.objectweb.org/wws
Reply | Threaded
Open this post in threaded view
|

Re: Nested Repeats, position()?

Ryan Puddephatt
Alex,
    Is there any talk of a similar function in Xforms 1.1?

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
w> www.teleflex.com

"Measuring programming progress by lines of code is like measuring aircraft building progress by weight." - Bill Gates
"If you lie to the compiler, it will get its revenge." - Henry Spencer
"It's hard enough to find an error in your code when you're looking for it; it's even harder when you've assumed your code is error-free." - Steve McConnell
"If builders built buildings the way programmers wrote programs, then the first woodpecker that came along would destroy civilization." - Gerald Weinberg



Alessandro Vernet wrote:
Chris,

On 6/6/07, ChrisSpeare [hidden email] wrote:
<xforms:select1 ref="/Country/IdentificationCode" model="model_SeaManifest"
>
        <xforms:action ev:event="xforms-value-changed">
                <xforms:setvalue
ref="instance('instance_model_SeaManifest')/ManifestInformation/Shipment[position()]/Schedule/RoutingPort/Country/Name"
value="instance('CountryList')/item[countryCode=instance('instance_model_SeaManifest')/ManifestInformation/Shipment[position()]/Schedule/RoutingPort/Country/IdentificationCode]/countryName"/>
        </xforms:action>
        ...
</xforms:select1>

Where the repeat was just shipment, however the repeat concerns a repeat on
routing port as well.  So how do I set the value of the inner item in the
context of a select1 action?

You are repeating on the Shipment element. I would use
xxforms:repeat-current() here. It is an extension, but it makes
expressions much simpler to understand. The value expression would
become:

instance('CountryList')/item[countryCode=xxforms:repeat-current()/Schedule/RoutingPort/Country/IdentificationCode]/countryName

Alex

-- 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: Nested Repeats, position()?

Alessandro Vernet
Administrator
Ryan,

On 6/7/07, Ryan Puddephatt <[hidden email]> wrote:
>      Is there any talk of a similar function in Xforms 1.1?

I'll also let Erik comment on this since he regularly attends the
group meetings. At the last face to face meeting, there has been talks
about supporting variables. A few people were favorable to the idea.
With variables, you could do:

<xforms:repeat nodeset="/company/department" >
    <xforms:variable name="current-department" select="."/>
    <!-- Then here is $current-department in expressions -->
</xforms:repeat>

BTW, you see features the working group is thinking about for the next
version of XForms on this publicly accessible wiki:

http://www.w3.org/MarkUp/Forms/wiki/XForms_Future_Features

Alex
--
Orbeon Forms - Web 2.0 Forms, open-source, for the Enterprise
http://www.orbeon.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
ObjectWeb mailing lists service home page: http://www.objectweb.org/wws
Reply | Threaded
Open this post in threaded view
|

Re: Nested Repeats, position()?

Erik Bruchez
Administrator
In reply to this post by Ryan Puddephatt
Unfortunately, I don't think this will make it into 1.1. But as Alex
pointed out, the working group is considering many features for future
versions.

-Erik

Ryan Puddephatt wrote:

> Alex,
>     Is there any talk of a similar function in Xforms 1.1?
>
> Ryan
>
> Ryan Puddephatt
> Software Engineer
>  
> Teleflex Group - IT UK
> 1 Michaelson Square
> Livingston
> West Lothian
> Scotland
> EH54 7DP
>  
> e> [hidden email] <mailto:[hidden email]>
> t> +44(0)1506 407 110
> f> +44(0)1506 407 108
> w> www.teleflex.com <http://www.teleflex.com>
>
> "Measuring programming progress by lines of code is like measuring
> aircraft building progress by weight." - /Bill Gates/
> "If you lie to the compiler, it will get its revenge." - /Henry Spencer/
> "It's hard enough to find an error in your code when you're looking for
> it; it's even harder when you've assumed your code is error-free." -
> /Steve McConnell/
> "If builders built buildings the way programmers wrote programs, then
> the first woodpecker that came along would destroy civilization." -
> /Gerald Weinberg/
>
>
>
> Alessandro Vernet wrote:
>> Chris,
>>
>> On 6/6/07, ChrisSpeare <[hidden email]> wrote:
>>> <xforms:select1 ref="/Country/IdentificationCode"
>>> model="model_SeaManifest"
>>> >
>>>         <xforms:action ev:event="xforms-value-changed">
>>>                 <xforms:setvalue
>>> ref="instance('instance_model_SeaManifest')/ManifestInformation/Shipment[position()]/Schedule/RoutingPort/Country/Name"
>>>
>>> value="instance('CountryList')/item[countryCode=instance('instance_model_SeaManifest')/ManifestInformation/Shipment[position()]/Schedule/RoutingPort/Country/IdentificationCode]/countryName"/>
>>>
>>>         </xforms:action>
>>>         ...
>>> </xforms:select1>
>>>
>>> Where the repeat was just shipment, however the repeat concerns a
>>> repeat on
>>> routing port as well.  So how do I set the value of the inner item in
>>> the
>>> context of a select1 action?
>>
>> You are repeating on the Shipment element. I would use
>> xxforms:repeat-current() here. It is an extension, but it makes
>> expressions much simpler to understand. The value expression would
>> become:
>>
>> instance('CountryList')/item[countryCode=xxforms:repeat-current()/Schedule/RoutingPort/Country/IdentificationCode]/countryName
>>
>>
>> Alex
>> ------------------------------------------------------------------------
>>
>>
>> --
>> 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 Forms - Web Forms for the Enterprise Done the Right Way
http://www.orbeon.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
ObjectWeb mailing lists service home page: http://www.objectweb.org/wws
Reply | Threaded
Open this post in threaded view
|

Re: Nested Repeats, position()?

Ryan Puddephatt
Thanks, I'll keep my eye out on the W3C List :-)

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
w> www.teleflex.com

"Measuring programming progress by lines of code is like measuring aircraft building progress by weight." - Bill Gates
"If you lie to the compiler, it will get its revenge." - Henry Spencer
"It's hard enough to find an error in your code when you're looking for it; it's even harder when you've assumed your code is error-free." - Steve McConnell
"If builders built buildings the way programmers wrote programs, then the first woodpecker that came along would destroy civilization." - Gerald Weinberg



Erik Bruchez wrote:
Unfortunately, I don't think this will make it into 1.1. But as Alex pointed out, the working group is considering many features for future versions.

-Erik

Ryan Puddephatt wrote:
Alex,
    Is there any talk of a similar function in Xforms 1.1?

Ryan

Ryan Puddephatt
Software Engineer
 
Teleflex Group - IT UK
1 Michaelson Square
Livingston
West Lothian
Scotland
EH54 7DP
 
e> [hidden email] [hidden email]
t> +44(0)1506 407 110
f> +44(0)1506 407 108
w> www.teleflex.com <http://www.teleflex.com>

"Measuring programming progress by lines of code is like measuring aircraft building progress by weight." - /Bill Gates/
"If you lie to the compiler, it will get its revenge." - /Henry Spencer/
"It's hard enough to find an error in your code when you're looking for it; it's even harder when you've assumed your code is error-free." - /Steve McConnell/
"If builders built buildings the way programmers wrote programs, then the first woodpecker that came along would destroy civilization." - /Gerald Weinberg/



Alessandro Vernet wrote:
Chris,

On 6/6/07, ChrisSpeare [hidden email] wrote:
<xforms:select1 ref="/Country/IdentificationCode" model="model_SeaManifest"
>
        <xforms:action ev:event="xforms-value-changed">
                <xforms:setvalue
ref="instance('instance_model_SeaManifest')/ManifestInformation/Shipment[position()]/Schedule/RoutingPort/Country/Name"
value="instance('CountryList')/item[countryCode=instance('instance_model_SeaManifest')/ManifestInformation/Shipment[position()]/Schedule/RoutingPort/Country/IdentificationCode]/countryName"/>
        </xforms:action>
        ...
</xforms:select1>

Where the repeat was just shipment, however the repeat concerns a repeat on
routing port as well.  So how do I set the value of the inner item in the
context of a select1 action?

You are repeating on the Shipment element. I would use
xxforms:repeat-current() here. It is an extension, but it makes
expressions much simpler to understand. The value expression would
become:

instance('CountryList')/item[countryCode=xxforms:repeat-current()/Schedule/RoutingPort/Country/IdentificationCode]/countryName

Alex
------------------------------------------------------------------------


--
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: [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