current() function in XForms XPath expressions?

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

current() function in XForms XPath expressions?

Larry T. Chen
Hi All,

Is there currently any support for a function similar to XSLT's current() in OPS?

The nature of the problem is decribed in the current XForms 1.1 requirements (http://www.w3.org/TR/xforms-11-req/), section 2.5:

Quoting from the above referenced document:

In some forms, it is necessary to perform a simple table lookup based on user input. For example, suppose a form contains an element conversionTable that provides conversion rates for various currencies to the user's local currency. Based on the conversion selected by the user, the appropriate exchange rate would be used in a calculation.

XPath provides the ability to perform this type of search using predicates. To continue the above example, suppose each child of conversionTable is a rate element with the exchange rate as content and a currency attribute. Further, let a separate instance element called currency provide the storage for the currency selected by the user, and let amount contain the amount to convert. The converted amount could then be obtained using the following XPath: /root/amount * /root/conversionTable/rate[@currency=/root/currency].

The problem with this approach is that it uses absolute referencing to obtain the currency value selected by the user. If the converted amount, amount, and currency elements were moved to a deeper point in the instance data, then the XPath would have to be rewritten.

Requirement: Allow an XPath expression to perform a table search using a key whose value is referenced relative to the initial context node of the XPath expression.

--end quote

Based on the example given in the snippet above, I'd like to be able do something like:
<xforms:bind nodeset="convertedAmount" calculate=
"../amount * /root/conversionTable/rate[@currency=current()/../currency]"/>
Note the use of current() like in XSLT to refer to the current context node outside of the predicate.
I hope that's clear enough.

So is this possible right now with OPS?   If not, I'd like to request it be implemented since it is a very common use case.  Without something like current(), it is impossible to perform a calculation on fields in a repeat element using values from a separate lookup table, since you cannot reference specific elements inside a repeat using an absolute path.

Larry T. Chen
Software Engineer
Intelenet Communications, Inc.


--
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: current() function in XForms XPath expressions?

Adrian Baker-2
For repeats you can you the xxforms:repeat-current() function (see http://www.orbeon.com/ops/doc/reference-xforms-ng#ops-extensions).

Also, in the past I've used the XPath 2.0 for expression to retain relative references, for example:

    for $currentNode  in . return instance('reference')/someLookupStuff[@id = $currentNode/@id]/name

Adrian

Larry T. Chen wrote:
Hi All,

Is there currently any support for a function similar to XSLT's current() in OPS?

The nature of the problem is decribed in the current XForms 1.1 requirements (http://www.w3.org/TR/xforms-11-req/), section 2.5:

Quoting from the above referenced document:

In some forms, it is necessary to perform a simple table lookup based on user input. For example, suppose a form contains an element conversionTable that provides conversion rates for various currencies to the user's local currency. Based on the conversion selected by the user, the appropriate exchange rate would be used in a calculation.

XPath provides the ability to perform this type of search using predicates. To continue the above example, suppose each child of conversionTable is a rate element with the exchange rate as content and a currency attribute. Further, let a separate instance element called currency provide the storage for the currency selected by the user, and let amount contain the amount to convert. The converted amount could then be obtained using the following XPath: /root/amount * /root/conversionTable/rate[@currency=/root/currency].

The problem with this approach is that it uses absolute referencing to obtain the currency value selected by the user. If the converted amount, amount, and currency elements were moved to a deeper point in the instance data, then the XPath would have to be rewritten.

Requirement: Allow an XPath expression to perform a table search using a key whose value is referenced relative to the initial context node of the XPath expression.

--end quote

Based on the example given in the snippet above, I'd like to be able do something like:
<xforms:bind nodeset="convertedAmount" calculate=
"../amount * /root/conversionTable/rate[@currency=current()/../currency]"/>
Note the use of current() like in XSLT to refer to the current context node outside of the predicate.
I hope that's clear enough.

So is this possible right now with OPS?   If not, I'd like to request it be implemented since it is a very common use case.  Without something like current(), it is impossible to perform a calculation on fields in a repeat element using values from a separate lookup table, since you cannot reference specific elements inside a repeat using an absolute path.

Larry T. Chen
Software Engineer
Intelenet Communications, Inc.

-- 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: current() function in XForms XPath expressions?

Erik Bruchez
Administrator
In reply to this post by Larry T. Chen
Larry,

The current() function is actually implemented, but it turns out it is
broken. I have entered a bug to track this:

http://forge.objectweb.org/tracker/index.php?func=detail&aid=305568&group_id=168&atid=350207

In the meanwhile you can use the trick mentioned by Adrian.

Also note that there is now an xxforms:context(id) function that returns
the context at the level of an enclosing element (xforms:group,
xforms:repeat, xforms:switch in particular).

-Erik

Larry T. Chen wrote:

> Hi All,
>
> Is there currently any support for a function similar to XSLT's
> current() in OPS?
>
> The nature of the problem is decribed in the current XForms 1.1
> requirements (http://www.w3.org/TR/xforms-11-req/), section 2.5:
>
> Quoting from the above referenced document:
>
> In some forms, it is necessary to perform a simple table lookup based on
> user input. For example, suppose a form contains an element
> |conversionTable| that provides conversion rates for various currencies
> to the user's local currency. Based on the conversion selected by the
> user, the appropriate exchange rate would be used in a calculation.
>
> XPath provides the ability to perform this type of search using
> predicates. To continue the above example, suppose each child of
> |conversionTable| is a |rate| element with the exchange rate as content
> and a |currency| attribute. Further, let a separate instance element
> called |currency| provide the storage for the currency selected by the
> user, and let |amount| contain the amount to convert. The converted
> amount could then be obtained using the following XPath: |/root/amount *
> /root/conversionTable/rate[@currency=/root/currency]|.
>
> The problem with this approach is that it uses absolute referencing to
> obtain the currency value selected by the user. If the converted amount,
> amount, and currency elements were moved to a deeper point in the
> instance data, then the XPath would have to be rewritten.
>
> /Requirement:/ Allow an XPath expression to perform a table search using
> a key whose value is referenced relative to the initial context node of
> the XPath expression.
>
> --end quote
>
> Based on the example given in the snippet above, I'd like to be able do
> something like:
> <xforms:bind nodeset="convertedAmount" calculate=
> |"../amount *
> /root/conversionTable/rate[@currency=current()/../currency]|"/>
> Note the use of current() like in XSLT to refer to the current context
> node outside of the predicate.
> I hope that's clear enough.
>
> So is this possible right now with OPS?   If not, I'd like to request it
> be implemented since it is a very common use case.  Without something
> like current(), it is impossible to perform a calculation on fields in a
> repeat element using values from a separate lookup table, since you
> cannot reference specific elements inside a repeat using an absolute path.
>
> Larry T. Chen
> Software Engineer
> Intelenet Communications, Inc.
>
>
> ------------------------------------------------------------------------
>
>
> --
> 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