Fwd: Pattern matching error in xsl:key

Ihe Onwuka <[email protected]> Sat, 5 Sep 2020 14:37:33 -0400
Newsgroups gmane.text.xml.saxon.help
Message-ID <CALfs7+wgEu4xO+=LvxQae7V4LBo4sHVLdZgGZtT-wFfSS75zhg@mail.gmail.com>
That's the reason the spec gives. I asked for the logical reason.

Perhaps you feel they are one and the same to me they are not because they
produce the  illogical end result that two things that are obviously equal
are not


On Sat, Sep 5, 2020 at 2:26 PM Dimitre Novatchev <[email protected]>
wrote:

> > What is the logical reason ( not the reason the spec gives,  the logical
> reason) for concluding that in the @from attribute below 4.0 is a string
> >
> > <changes from="4.0" to="4.1">
> >     <rename>
> >         <metadata/>
> >      </rename>
> >   </changes>
> >
> > Isn't it obviously a decimal number?
>
> The short answer is that these are not "select" attributes in an XSLT
> instruction.
>
> The complete answer is in the XPath 2.0 specification (
> https://www.w3.org/TR/xpath20/#id-typed-value):
>
> "The typed value of an attribute node with the type annotation
> <https://www.w3.org/TR/xpath20/#dt-type-annotation> xs:anySimpleType or
> xs:untypedAtomic is the same as its string value, as an instance of
> xs:untypedAtomic."
>
> So, unless the type of an attribute is specified in an xml schema to be
> something different than xs:anySimpleType or xs:untypedAtomic, then its
> typed value is the same as its string value, so this value is treated as a
> string.
>
> Cheers,
> Dimitre
>
>
>
> On Sat, Sep 5, 2020 at 11:08 AM Ihe Onwuka <[email protected]> wrote:
>
>>
>> On Sat, Sep 5, 2020 at 1:54 PM Dimitre Novatchev <[email protected]>
>> wrote:
>>
>>> > So I have ended up doing an eq comparison and quoting the $source and
>>> $target, which is what I was trying to avoid.
>>>
>>> Why do you think any logical reasoning would result in deciding that the
>>> type of $source below must be a string?
>>>
>>> >  <xsl:param name="source" select="4.0"/>
>>>
>>> The value of the "select" attribute is evaluated as an XPath expression,
>>> What is the type of the xpath expression (hint: it is obviously a decimal
>>> number):
>>>
>>>    4.0
>>>
>>> Why do you think anyone should conclude that this is a string?
>>>
>>> Just curious...
>>>
>>> Cheers,
>>> Dimitre
>>>
>>>
>> Of course there is no logical reason for anyone to conclude that 4.0 is a
>> string.
>> Of course it's obviously a decimal number.
>>
>> So now let's apply that logic to the other half of the problem.
>>
>> What is the logical reason ( not the reason the spec gives,  the logical
>> reason) for concluding that in the @from attribute below 4.0 is a string
>>
>> <changes from="4.0" to="4.1">
>>      <rename>
>>         <metadata/>
>>      </rename>
>>   </changes>
>>
>> Isn't it obviously a decimal number?
>>
>>
>> On Sat, Sep 5, 2020 at 10:49 AM Ihe Onwuka <[email protected]> wrote:
>>>
>>>>
>>>>
>>>> On Sat, Sep 5, 2020 at 11:56 AM Martin Honnen <[email protected]>
>>>> wrote:
>>>>
>>>>> Am 05.09.2020 um 17:34 schrieb Ihe Onwuka:
>>>>>
>>>>> > No doubt in excerpting I omitted some relevant info. I'll try and fix
>>>>> > that. The XML content is in a separate document and globally
>>>>> namespaced.
>>>>> > Here.
>>>>> >
>>>>> > <versionChanges xmlns="http://changes" >
>>>>> >    <changes from="4.0" to="4.1">
>>>>> >       <rename>
>>>>> >          <metadata/>
>>>>> >       </rename>
>>>>> >    </changes>
>>>>> > </versionChanges>
>>>>> >
>>>>> > and here is the error message
>>>>> >
>>>>> > Warning at char 11 in xsl:key/@match on line 36 column 111 of
>>>>> > myStylesheet.xsl:
>>>>> >    XPTY0004  An error occurred matching pattern
>>>>> >
>>>>> > {element(Q{http://changes}changes)[((data(attribute::attribute(Q{}from)))
>>>>> eq
>>>>> >    (atomizeSingleton($source))) and
>>>>> ((data(attribute::attribute(Q{}to))) eq
>>>>> >    (atomizeSingleton($target)))]}:
>>>>> >
>>>>> >     My guess would be that it's a type error connected with the fact
>>>>> >     you're comparing numbers to strings, but beyond that,
>>>>> >
>>>>> >
>>>>> > I am comparing parameters whose values are 4.0 and 4.1 respectively
>>>>> to
>>>>> > attributes whose values are 4.0 and 4.1 respectively. Saxon has made
>>>>> > it's own assumptions about what types they are and come up with that
>>>>> error.
>>>>>
>>>>> The types are not made up by Saxon but are defined in the XPath/XSLT
>>>>> specs. In the XSLT code if you declare
>>>>>
>>>>>    <xsl:param name="source" select="4.0"/>
>>>>>
>>>>> the expression 4.0 in the select attribute is of type xs:decimal (in a
>>>>> version="2.0" or version="3.0" XSLT code).
>>>>>
>>>>> However, in your untyped XML the attribute value of e.g. @from or @to
>>>>> is
>>>>> of type xs:untypedAtomic.
>>>>>
>>>>> The eq operator only works if both operands have a comparable type, in
>>>>> your case the rules in
>>>>> https://www.w3.org/TR/xpath-31/#id-value-comparisons (5.d) give
>>>>> "Otherwise, a type error is raised [err:XPTY0004].".
>>>>>
>>>>> So using = instead of eq is one way to avoid that, as it in 4.a of
>>>>> https://www.w3.org/TR/xpath-31/#id-general-comparisons stipulates: "If
>>>>> at least one of the two atomic values is an instance of a numeric type,
>>>>> then both atomic values are converted to the type xs:double by applying
>>>>> the fn:number function".
>>>>>
>>>>>
>>>> Correction to my earlier post.
>>>> Using = instead of eq changes the behaviour of the program and it ends
>>>> up incorrectly omitting some of the output.
>>>>
>>>> I'm not going to investigate why because I shouldn't be using an
>>>> existential evaluator anyway.
>>>>
>>>> So I have ended up doing an eq comparison and quoting the $source and
>>>> $target, which is what I was trying to avoid.
>>>>
>>>>
>>>>
>>>> _______________________________________________
>>>> saxon-help mailing list archived at http://saxon.markmail.org/
>>>> [email protected]
>>>> https://lists.sourceforge.net/lists/listinfo/saxon-help
>>>
>>>
>>>
>>> --
>>> Cheers,
>>> Dimitre Novatchev
>>> ---------------------------------------
>>> Truly great madness cannot be achieved without significant intelligence.
>>> ---------------------------------------
>>> To invent, you need a good imagination and a pile of junk
>>> -------------------------------------
>>> Never fight an inanimate object
>>> -------------------------------------
>>> To avoid situations in which you might make mistakes may be the
>>> biggest mistake of all
>>> ------------------------------------
>>> Quality means doing it right when no one is looking.
>>> -------------------------------------
>>> You've achieved success in your field when you don't know whether what
>>> you're doing is work or play
>>> -------------------------------------
>>> To achieve the impossible dream, try going to sleep.
>>> -------------------------------------
>>> Facts do not cease to exist because they are ignored.
>>> -------------------------------------
>>> Typing monkeys will write all Shakespeare's works in 200yrs.Will they
>>> write all patents, too? :)
>>> -------------------------------------
>>> Sanity is madness put to good use.
>>> -------------------------------------
>>> I finally figured out the only reason to be alive is to enjoy it.
>>>
>>>
>>
>
> --
> Cheers,
> Dimitre Novatchev
> ---------------------------------------
> Truly great madness cannot be achieved without significant intelligence.
> ---------------------------------------
> To invent, you need a good imagination and a pile of junk
> -------------------------------------
> Never fight an inanimate object
> -------------------------------------
> To avoid situations in which you might make mistakes may be the
> biggest mistake of all
> ------------------------------------
> Quality means doing it right when no one is looking.
> -------------------------------------
> You've achieved success in your field when you don't know whether what
> you're doing is work or play
> -------------------------------------
> To achieve the impossible dream, try going to sleep.
> -------------------------------------
> Facts do not cease to exist because they are ignored.
> -------------------------------------
> Typing monkeys will write all Shakespeare's works in 200yrs.Will they
> write all patents, too? :)
> -------------------------------------
> Sanity is madness put to good use.
> -------------------------------------
> I finally figured out the only reason to be alive is to enjoy it.
>
>

_______________________________________________
saxon-help mailing list archived at http://saxon.markmail.org/
[email protected]
https://lists.sourceforge.net/lists/listinfo/saxon-help