position() in a repeat

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

position() in a repeat

Park, Michael

Hi All,

 

Is it possible to reference another instance using position() from within a repeat?  I cannot get this to work successfully.

 

In other words I’d like to use a repeat to reference nodes in another instance at the same position. 

 

Ie., when repeating at position 2, reference position 2 in a separate instance.

 

<xforms:repeat nodeset="instance('main')/child" id="repeat">                                                                                          

   <xforms:output value="position()">

      <xforms:label>Position = </xforms:label>

   </xforms:output>

   <xforms:output ref="instance('test')/test[position()]">

      <xforms:label>Value = </xforms:label>

   </xforms:output>                    

</xforms:repeat>

 

Here is a link to the full example: http://dl.lib.brown.edu/mwp/xforms/test2.xhtml

 

 

Thanks,

Mike

 



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

RE: position() in a repeat

Gerrit Germis-2

Hi Michael,

 

We had a similar issue, and solved it by using xxforms:evaluate to get to the other instance data:

 

This constructs an XPath dynamically using the “id” attribute of the node we’re looping on. It finds a node with the same id in another instance:

 

<xforms:output ref=”xxforms:evaluate(concat('instance(''other-instance'')/somewhere/node[. = ', @Id, ']'))" at="1"/>

 

Hope this helps,

Gerrit

 

 


From: Park, Michael [mailto:[hidden email]]
Sent: Tuesday, November 27, 2007 16:36 PM
To: [hidden email]
Subject: [ops-users] position() in a repeat

 

Hi All,

 

Is it possible to reference another instance using position() from within a repeat?  I cannot get this to work successfully.

 

In other words I’d like to use a repeat to reference nodes in another instance at the same position. 

 

Ie., when repeating at position 2, reference position 2 in a separate instance.

 

<xforms:repeat nodeset="instance('main')/child" id="repeat">                                                                                          

   <xforms:output value="position()">

      <xforms:label>Position = </xforms:label>

   </xforms:output>

   <xforms:output ref="instance('test')/test[position()]">

      <xforms:label>Value = </xforms:label>

   </xforms:output>                    

</xforms:repeat>

 

Here is a link to the full example: http://dl.lib.brown.edu/mwp/xforms/test2.xhtml

 

 

Thanks,

Mike

 



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

RE: position() in a repeat

Park, Michael

Thx! 

 

I’d like to try it.  However, I haven’t seen any real docs on how to use it.  I’ll break yours apart and see if I can get it working. 

 

I won’t actually be using it in an output.  I just did that to test.

 

-Mike

 


From: Gerrit Germis [mailto:[hidden email]]
Sent: Tuesday, November 27, 2007 11:13 AM
To: [hidden email]
Subject: RE: [ops-users] position() in a repeat

 

Hi Michael,

 

We had a similar issue, and solved it by using xxforms:evaluate to get to the other instance data:

 

This constructs an XPath dynamically using the “id” attribute of the node we’re looping on. It finds a node with the same id in another instance:

 

<xforms:output ref=”xxforms:evaluate(concat('instance(''other-instance'')/somewhere/node[. = ', @Id, ']'))" at="1"/>

 

Hope this helps,

Gerrit

 

 


From: Park, Michael [mailto:[hidden email]]
Sent: Tuesday, November 27, 2007 16:36 PM
To: [hidden email]
Subject: [ops-users] position() in a repeat

 

Hi All,

 

Is it possible to reference another instance using position() from within a repeat?  I cannot get this to work successfully.

 

In other words I’d like to use a repeat to reference nodes in another instance at the same position. 

 

Ie., when repeating at position 2, reference position 2 in a separate instance.

 

<xforms:repeat nodeset="instance('main')/child" id="repeat">                                                                                          

   <xforms:output value="position()">

      <xforms:label>Position = </xforms:label>

   </xforms:output>

   <xforms:output ref="instance('test')/test[position()]">

      <xforms:label>Value = </xforms:label>

   </xforms:output>                    

</xforms:repeat>

 

Here is a link to the full example: http://dl.lib.brown.edu/mwp/xforms/test2.xhtml

 

 

Thanks,

Mike

 



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

RE: position() in a repeat

Park, Michael
In reply to this post by Gerrit Germis-2

Thanks Gerrit! 

 

It worked when I changed it to:

 

  <xforms:output ref="xxforms:evaluate(  concat('instance(''test'')/test[', position(), ']')  )">

 


From: Gerrit Germis [mailto:[hidden email]]
Sent: Tuesday, November 27, 2007 11:13 AM
To: [hidden email]
Subject: RE: [ops-users] position() in a repeat

 

Hi Michael,

 

We had a similar issue, and solved it by using xxforms:evaluate to get to the other instance data:

 

This constructs an XPath dynamically using the “id” attribute of the node we’re looping on. It finds a node with the same id in another instance:

 

<xforms:output ref=”xxforms:evaluate(concat('instance(''other-instance'')/somewhere/node[. = ', @Id, ']'))" at="1"/>

 

Hope this helps,

Gerrit

 

 


From: Park, Michael [mailto:[hidden email]]
Sent: Tuesday, November 27, 2007 16:36 PM
To: [hidden email]
Subject: [ops-users] position() in a repeat

 

Hi All,

 

Is it possible to reference another instance using position() from within a repeat?  I cannot get this to work successfully.

 

In other words I’d like to use a repeat to reference nodes in another instance at the same position. 

 

Ie., when repeating at position 2, reference position 2 in a separate instance.

 

<xforms:repeat nodeset="instance('main')/child" id="repeat">                                                                                          

   <xforms:output value="position()">

      <xforms:label>Position = </xforms:label>

   </xforms:output>

   <xforms:output ref="instance('test')/test[position()]">

      <xforms:label>Value = </xforms:label>

   </xforms:output>                    

</xforms:repeat>

 

Here is a link to the full example: http://dl.lib.brown.edu/mwp/xforms/test2.xhtml

 

 

Thanks,

Mike

 



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

Re: position() in a repeat

David McIntyre
In reply to this post by Park, Michael
Since the other solution works for you, then all is well.  But there's another tool to add to your XPath toolbox, which is using a trivial for-loop to create a local variable.

The problem with the original XPath expression you had, "instance('test')/test[position()]", is that the "position()" method is being called in the context of the "instance('test')/test" node rather than the original context.

To explain more fully, any time you have an XPath expression like "<XPath>[<number>]", that is a shorthand for "<XPath>[position() = <number>]" and it selects all those elements at <XPath> for which their position (among all nodes at <XPath>) is equal to <number>.  In this case, it will select all those nodes matching the path "instance('test')/test" for which their position is equal to their position, namely all of them!  Just to add to the confusion, I believe that only the first would show up in the output.

The trick is to evaluate the position() first, to get a value, and then pass that value to the [<number>] predicate.

So what you would use is "for $posision in position() return instance('test')/test[$position]".

I hope this helps, and my explanation is not too woolly.

Cheers,

   Dave Mc

----- Original Message -----
From: "Michael Park" <[hidden email]>
To: [hidden email]
Sent: 28 November 2007 05:52:31 o'clock (GMT+1200) Auto-Detected
Subject: RE: [ops-users] position() in a repeat


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

RE: position() in a repeat

Park, Michael
Dave,

I really appreciate that.  It clears up a lot of confusion.  And you
were correct on the output.  

I like the variable solution.  I wasn't aware of the fact I could store
it like that.  I was thinking a variable is exactly what I needed.
However, I've never seen that syntax used in xforms before.  Could you
point me to an example?
 
Thanks!
-Mike

-----Original Message-----
From: David McIntyre [mailto:[hidden email]]
Sent: Tuesday, November 27, 2007 4:16 PM
To: [hidden email]
Subject: Re: [ops-users] position() in a repeat

Since the other solution works for you, then all is well.  But there's
another tool to add to your XPath toolbox, which is using a trivial
for-loop to create a local variable.

The problem with the original XPath expression you had,
"instance('test')/test[position()]", is that the "position()" method is
being called in the context of the "instance('test')/test" node rather
than the original context.

To explain more fully, any time you have an XPath expression like
"<XPath>[<number>]", that is a shorthand for "<XPath>[position() =
<number>]" and it selects all those elements at <XPath> for which their
position (among all nodes at <XPath>) is equal to <number>.  In this
case, it will select all those nodes matching the path
"instance('test')/test" for which their position is equal to their
position, namely all of them!  Just to add to the confusion, I believe
that only the first would show up in the output.

The trick is to evaluate the position() first, to get a value, and then
pass that value to the [<number>] predicate.

So what you would use is "for $posision in position() return
instance('test')/test[$position]".

I hope this helps, and my explanation is not too woolly.

Cheers,

   Dave Mc

----- Original Message -----
From: "Michael Park" <[hidden email]>
To: [hidden email]
Sent: 28 November 2007 05:52:31 o'clock (GMT+1200) Auto-Detected
Subject: RE: [ops-users] position() in a repeat


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

Re: position() in a repeat

David McIntyre
Mike,

I don't know off-hand of any examples which use the trick specifically to pass a single variable to a predicate rather than to construct a sequence of values.  But the reference for the syntax for the "for" expression, including examples, is at http://www.w3.org/TR/xpath20/#id-for-expressions.  The key point is that the expression works perfectly well even when the ForClause is just a sequence with only one value.

Cheers,

   Dave Mc.

----- Original Message -----
From: "Michael Park" <[hidden email]>
To: [hidden email]
Sent: 28 November 2007 10:42:28 o'clock (GMT+1200) Auto-Detected
Subject: RE: [ops-users] position() in a repeat

Dave,

I really appreciate that.  It clears up a lot of confusion.  And you
were correct on the output.  

I like the variable solution.  I wasn't aware of the fact I could store
it like that.  I was thinking a variable is exactly what I needed.
However, I've never seen that syntax used in xforms before.  Could you
point me to an example?
 
Thanks!
-Mike




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

Re: position() in a repeat

Erik Bruchez
Administrator
In reply to this post by Park, Michael
As pointed out, this syntax is not part of XForms: it is part of XPath  
2.0.

Note that XPath 2.0 is not yet officially part of XForms, but the  
XForms Working Group at W3C hopes to integrate XPath 2.0 in XForms  
2.0. At Orbeon, we don't think we can live with just XPath 1.0 so we  
have decided to support XPath 2.0.

-Erik

On Nov 27, 2007, at 1:42 PM, Park, Michael wrote:

> Dave,
>
> I really appreciate that.  It clears up a lot of confusion.  And you
> were correct on the output.
>
> I like the variable solution.  I wasn't aware of the fact I could  
> store
> it like that.  I was thinking a variable is exactly what I needed.
> However, I've never seen that syntax used in xforms before.  Could you
> point me to an example?
>
> Thanks!
> -Mike
>
> -----Original Message-----
> From: David McIntyre [mailto:[hidden email]]
> Sent: Tuesday, November 27, 2007 4:16 PM
> To: [hidden email]
> Subject: Re: [ops-users] position() in a repeat
>
> Since the other solution works for you, then all is well.  But there's
> another tool to add to your XPath toolbox, which is using a trivial
> for-loop to create a local variable.
>
> The problem with the original XPath expression you had,
> "instance('test')/test[position()]", is that the "position()" method  
> is
> being called in the context of the "instance('test')/test" node rather
> than the original context.
>
> To explain more fully, any time you have an XPath expression like
> "<XPath>[<number>]", that is a shorthand for "<XPath>[position() =
> <number>]" and it selects all those elements at <XPath> for which  
> their
> position (among all nodes at <XPath>) is equal to <number>.  In this
> case, it will select all those nodes matching the path
> "instance('test')/test" for which their position is equal to their
> position, namely all of them!  Just to add to the confusion, I believe
> that only the first would show up in the output.
>
> The trick is to evaluate the position() first, to get a value, and  
> then
> pass that value to the [<number>] predicate.
>
> So what you would use is "for $posision in position() return
> instance('test')/test[$position]".
>
> I hope this helps, and my explanation is not too woolly.
>
> Cheers,
>
>   Dave Mc
>
> ----- Original Message -----
> From: "Michael Park" <[hidden email]>
> To: [hidden email]
> Sent: 28 November 2007 05:52:31 o'clock (GMT+1200) Auto-Detected
> Subject: RE: [ops-users] position() in a repeat
>
>
> --
> 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
--
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
OW2 mailing lists service home page: http://www.ow2.org/wws