[xquery-talk] Function for determining one XPath as subset of another

Adam Retter adam.retter at googlemail.com
Thu Jan 28 05:56:23 PST 2016


Hi Ghislain,

No I have not considered error cases, for the moment it is enough for
me to just raise an error if the path is invalid. Although in this
case I can assume that all paths I am provided are correct.

On 28 January 2016 at 13:44, Ghislain Fourny <g at 28.io> wrote:
> Hi Adam,
>
> This may sound stupid, but: have you considered that (and would it be
> relevant to you that) the second expression may raise errors that the first
> one wouldn't have raised, rather than returning a subset?
>
> Consider the case where b has a numeric type, and the attribute a cannot be
> cast to double?
>
> Kind regards,
> Ghislain
>
>
> On Thu, Jan 28, 2016 at 2:17 PM, Pavel Velikhov <pavel.velikhov at gmail.com>
> wrote:
>>
>> No, the first line in the base case should also return false, sorry
>>
>> >
>> >
>> > So suppose you have 2 path expressions, p1 and p2, and you allow only /x
>> > or //x as path steps
>> > and each path step can have a predicate:
>> >
>> > p1 = axis_1 pred_1, …, axis_n pred_n
>> > p2 = axis_1 pred_1, … , axis_m pred_m
>> >
>> > subsumes(p1, p2):
>> >  /* recursion base case */
>> >  if p1 is empty: return true
>> >  if p2 is empty: return false
>> >
>> >  a_1 = first axis of p1
>> >  a_2 = first axis of p2
>> >
>> >  if a_1 is a child axis ‘/‘ label l :
>> >   if a_2 is a child axis ‘/' with the same label l, and the predicates
>> > are equivalent:
>> >      return subsumes(p1 - a_1, p2 - a_2)
>> >   else:
>> >      return false
>> >
>> >   if a_1 is a descendants axis ‘//‘ with label l:
>> >     if p2 contains an axis with label l:
>> >        p2’ = remove all axes of p2 from the head, until you find an axis
>> > with label l
>> >        p2’ = remove the axis with label l from p2'
>> >        return subsumes( p_1 - a_1, p2’ )
>> >
>> >  return false
>>
>>
>> _______________________________________________
>> talk at x-query.com
>> http://x-query.com/mailman/listinfo/talk
>
>
>
> _______________________________________________
> talk at x-query.com
> http://x-query.com/mailman/listinfo/talk



-- 
Adam Retter

skype: adam.retter
tweet: adamretter
http://www.adamretter.org.uk



More information about the talk mailing list