Re: [SCXML] Incorrect XPath expressions in IR tests 153 & 155

Zjnue Brzavi <[email protected]> Mon, 9 Feb 2015 23:38:00 +0100
Newsgroups gmane.comp.web.voice
Message-ID <CABmmmmwh_VrW_r8wXngVRweGR83gvwtkRHKa_BdyXst0cMF+GA@mail.gmail.com>
--047d7bdc87a231d8a9050eaf6c98
Content-Type: text/plain; charset=ISO-8859-1

Hi Ate and Jim,

Firstly, apologies as I've been mistaken regarding test 153. My
implementation only tested the XPath specific tests, as are listed here:
https://github.com/zjnue/hscxml/commit/6d0d7318ca847f876d7755da8633c92c022a4766

Secondly, I do remember now making a workaround when setting an XML
variable.
While defining variables the normal <data id"varname">...</data> way, I've
had to change that strategy when the value passed in was already of type
XML (used in my implementation for foreach cases only I think):
https://github.com/zjnue/hscxml/blob/master/src/hsm/scxml/Model.hx#L426-L429

This I believe makes test483 pass, which contains a foreach.

On the whole I don't mind admitting that I've tried to take shortest paths
with my XPath datamodel implementation, as I've not had the time for it and
the sole purpose of the effort was simply to help the spec proceed to next
stages. I completely agree that this datamodel has been quite a challenge,
let alone finding a solid XPath library.
Given these considerations and that my implementation has only concerned
itself with a small subset of the test suite, it is not well placed to make
any claims, although it does already offer a fair bit of functionality.

Happy to hear how these matters conclude and all my respect goes to those
persisting with it.

Best wishes,
Zjnue


On Mon, Feb 9, 2015 at 11:17 PM, Jim Barnett <[email protected]> wrote:

>  Ate,
>   Questions about the XPath datamodel are always tricky, because the
> group's XPath experts haven't participated in several years.  ( I'm
> certainly not an XPath expert.)  However as I recall our past discussions
> of this issue, the consensus was with Zjnue's interpretation.
> Specifically, the requirement for the creation of a <data> node holds for
> top-level <data> elements only.  Furthermore, the intent was that <foreach>
> would have what you call 'transient pointers' to the array elements.  In
> particular, we intended that modifications to those array elements in the
> course of <foreach> would remain in effect after the <foreach> terminated.
> Specifically, when we say "The SCXML processor *MUST* act as if it has
> made a shallow copy of the collection produced by the evaluation of
> 'array'" the intent was that _only_ a  shallow copy be made and that it be
> possible to access the array elements directly.
>
> Tests 150 and 151 use the same list as tests 153 and 155.  (The .txml file
> has <conf:array123> and the xslt transform produces the <node> elements.)
> So I would expect all 4 tests to work the same way, with the XPath variable
> bound to the <node> elements in turn.  150 and 151 do not test that the
> newly created variable is initially bound to a <data> element.  (Actually,
> all tests 150 and 151 do is check that using a <foreach> with a previously
> undeclared variable does not raise an error.  The tests are rather bogus
> because the <foreach> doesn't do anything, but I was trying to keep the
> test simple and avoid extra logic that might introduce subtle errors.)
>
>  As for test 463, it is explicitly testing the structure of a variable
> created by the <data> element.  I don't think it is required that _any_
> XPath variable that occurs in an SCXML document have that structure.  I
> admit that this leaves open the question of what structure such other
> variables should have. As the spec stands, it is implementation-specific.
> However, we did intend for the behavior inside <foreach> to be what Zjnue
> describes.
>
> I'm willing to be persuaded that we're wrong, though.  It may well be that
> our intended interpretation causes problems that we did not foresee.
>
> - Jim
> P.S. Everyone who has worked with the XPath data model has had problems
> with it.
>
>
>
>  On 2/9/2015 4:20 PM, Ate Douma wrote:
>
> Hi Zjnue,
>
>
> On 2015-02-09 19:28, Zjnue Brzavi wrote:
>
> Hi Ate,
>
>        <datamodel>
>          <data id="Var1" expr="0"/>
>          <data id="Var2"/>
>          <data id="Var3">
>            <node xmlns="">1</node><node xmlns="">2</node><node
> xmlns="">3</node>
>          </data>
>          <data id="Var4" expr="1"/>
>        </datamodel>
>
> [..]
>
>     The "Var2/text()" xpath expressions in the if condition check and the
>     assignment value expression above are not valid/usable in this
> context.
>
>     The foreach element will assign each of the Var3 <node>x</node>
> children to
>     the Var2 variable, and the Var2 variable (its data node) thus will
> contains
>     no (direct) text node children, only a (single) "node" child.
>
>     To access the actual text value of that "node" child, the expression
> must
>     be: "$Var2/*/text()" or if desired "$Var2/node[1]/text()".
>
>
> This is something I've implemented also, and on this rare occasion I have
> to
> disagree with the suggestion.
>
> Let's take this SO post as context:
>
> http://stackoverflow.com/questions/11744465/xpath-difference-between-node-and-text
>
> Now back to the example you've stated.
> Var3 evaluates to an XMLList, which has this simplified structure:
>
> element node (name="node")
>      text node (value="1")
> element node (name="node")
>      text node (value="2")
> element node (name="node")
>      text node (value="3")
>
> Now, in the foreach structure, as we iterate through this list, we assign
> a
> reference to the next element node to Var2.
> In turn, $Var2/text() evaluates to 1, 2 and 3 as we expect.
>
> My guess is that your implementation creates a new XML instance when
> assigning
> values to Var2, giving it values such as:
>
> root node
>      element node (name="node")
>          text node (value="1")
>
> root node
>      element node (name="node")
>          text node (value="2")
>
> and so on, thereby requiring the extra axis specifier as you suggested:
> $Var2/*/text()   OR  $Var2/node[1]/text()
>
> However, as we are dealing with a complex type, I believe it is wrong to
> create
> new instances and that we should use references to the existing nodes,
> making
> the tests valid as they are currently specified.
>
> In my implementation, I have a normalized foreach routine for the
> different
> datamodels:
>
> https://github.com/zjnue/hscxml/blob/master/src/hsm/scxml/Interp.hx#L935-L972
>
> This works well for the tests mentioned, when I feed it with an array
> containing
> references to the different nodes in the XMLList, formed here:
>
> https://github.com/zjnue/hscxml/blob/master/src/hsm/scxml/Model.hx#L354-L366
>
> Do you agree?
>
>
> I agree such a solution was what I also implemented initially.
>
> However I changed my view on it and now implemented an actual item copy
> assignment to the variable <data> node, and even create such a <data> node
> first if it doesn't yet exist (as required and tested by tests 150 and
> 151).
>
> The reason I changed my implementation is that the wording in the
> specification and the tests made me conclude that the intent is that XPath
> variables (in SCXML) always (must) refer to an actual <data> node with an
> id equal to the variable name.
>
> In the solution you implemented the XPath variable *initially* refers to
> such a <data> node, but then loses its binding/reference to a datamodel
> <data> node and becomes a 'transient' reference to the intermediate array
> items.
>
> Although I'd also rather and more optimally would like to use the XPath
> variables as transient pointers, the spec wording and IR tests don't seem
> to agree with that.
> Your implementation maybe passes each individual tests, but if rules and
> semantics checked in one test should also apply in other tests, then IMO
> your solution no longer is or would be valid.
>
> Note for example that such transient XPath variable no longer will agree
> to an XPath test like "local-name($Var2)=='data' and '$Var2@id='Var2'",
> something test 463 is testing. Of course not in the context of a <foreach>,
> but I assume(d?) such XPath variable conditions should always be true.
>
> One thing which seems to be required anyway is that if a <foreach> item or
> index doesn't exist yet, at least a Node element must be created to hold
> the variable data, as for example is checked by tests 150 and 151.
>
> Note also that in test 151 the index variable, which just 'holds' a
> number, still requires creating a Node variable because of the final test
> condition ""$Var5/* or $Var5/text()".
> A 'normal' XPath variable perfectly well can point to just a number value,
> however the SCXML spec (and/or tests) require even for such variables an
> actual (data) node element.
>
> But, maybe I've been assuming and interpreting too much into this...
> Trying to get the xpath datamodel implementation working properly, and as
> intended, has been (and still is) quite a challenge so say the least.
>
> Maybe Jim can chime in and help clarify what the actual or intended
> requirements concerning XPath variables are.
>
> Thanks, Ate
>
>
> Best regards,
> Zjnue
>
>
>
>
>

--047d7bdc87a231d8a9050eaf6c98
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><div><div><div><div><div><div>Hi Ate and Jim,<br><br></div=
>Firstly, apologies as I&#39;ve been mistaken regarding test 153. My implem=
entation only tested the XPath specific tests, as are listed here:<br><a hr=
ef=3D"https://github.com/zjnue/hscxml/commit/6d0d7318ca847f876d7755da8633c9=
2c022a4766">https://github.com/zjnue/hscxml/commit/6d0d7318ca847f876d7755da=
8633c92c022a4766</a><br><br></div>Secondly, I do remember now making a work=
around when setting an XML variable.<br></div>While defining variables the =
normal &lt;data id&quot;varname&quot;&gt;...&lt;/data&gt; way, I&#39;ve had=
 to change that strategy when the value passed in was already of type XML (=
used in my implementation for foreach cases only I think): <a href=3D"https=
://github.com/zjnue/hscxml/blob/master/src/hsm/scxml/Model.hx#L426-L429">ht=
tps://github.com/zjnue/hscxml/blob/master/src/hsm/scxml/Model.hx#L426-L429<=
/a><br><br></div>This I believe makes test483 pass, which contains a foreac=
h.<br><br></div>On the whole I don&#39;t mind admitting that I&#39;ve tried=
 to take shortest paths with my XPath datamodel implementation, as I&#39;ve=
 not had the time for it and the sole purpose of the effort was simply to h=
elp the spec proceed to next stages. I completely agree that this datamodel=
 has been quite a challenge, let alone finding a solid XPath library.<br></=
div>Given these considerations and that my implementation has only concerne=
d itself with a small subset of the test suite, it is not well placed to ma=
ke any claims, although it does already offer a fair bit of functionality.<=
br><div><div><div><br><div>Happy to hear how these matters conclude and all=
 my respect goes to those persisting with it.<br><br></div><div>Best wishes=
,<br>Zjnue<br></div><div><br></div></div></div></div></div><div class=3D"gm=
ail_extra"><br><div class=3D"gmail_quote">On Mon, Feb 9, 2015 at 11:17 PM, =
Jim Barnett <span dir=3D"ltr">&lt;<a href=3D"mailto:[email protected]" t=
arget=3D"_blank">[email protected]</a>&gt;</span> wrote:<br><blockquote =
class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid=
;padding-left:1ex">
 =20
   =20
 =20
  <div bgcolor=3D"#FFFFFF" text=3D"#000000">
    Ate,<br>
    =A0 Questions about the XPath datamodel are always tricky, because the
    group&#39;s XPath experts haven&#39;t participated in several years.=A0=
 ( I&#39;m
    certainly not an XPath expert.)=A0 However as I recall our past
    discussions of this issue, the consensus was with Zjnue&#39;s
    interpretation.=A0 Specifically, the requirement for the creation of a
    &lt;data&gt; node holds for top-level &lt;data&gt; elements only.=A0
    Furthermore, the intent was that &lt;foreach&gt; would have what you
    call &#39;transient pointers&#39; to the array elements.=A0 In particul=
ar, we
    intended that modifications to those array elements in the course of
    &lt;foreach&gt; would remain in effect after the &lt;foreach&gt;
    terminated.=A0 Specifically, when we say &quot;<a name=3D"14b706d1e0991=
66f_N108BE">The
      SCXML processor <em title=3D"MUST in RFC2119 context">MUST</em> act a=
s if it has made a shallow copy
      of the collection
      produced by the evaluation of &#39;array&#39;&quot; the intent was th=
at _only_
      a=A0 shallow copy be made and that it be possible to access the
      array elements directly.=A0=A0=A0=A0=A0 <br>
      <br>
      Tests 150 and 151 use the same list as tests 153 and 155.=A0 (The
      .txml file has &lt;conf:array123&gt; and the xslt transform
      produces the &lt;node&gt; elements.)=A0 So I would expect all 4
      tests to work the same way, with the XPath variable bound to the
      &lt;node&gt; elements in turn.=A0 150 and 151 do not test that the
      newly created variable is initially bound to a &lt;data&gt;
      element.=A0 (Actually, all tests 150 and 151 do is check that using
      a &lt;foreach&gt; with a previously undeclared variable does not
      raise an error.=A0 The tests are rather bogus because the
      &lt;foreach&gt; doesn&#39;t do anything, but I was trying to keep the
      test simple and avoid extra logic that might introduce subtle
      errors.)=A0 <br>
      <br>
      =A0As for test 463, it is explicitly testing the structure of a
      variable created by the &lt;data&gt; element.=A0 I don&#39;t think it=
 is
      required that _any_ XPath variable that occurs in an SCXML
      document have that structure.=A0 I admit that this leaves open the
      question of what structure such other variables should have. As
      the spec stands, it is implementation-specific.=A0 However, we did
      intend for the behavior inside &lt;foreach&gt; to be what Zjnue
      describes. =A0=A0 <br>
      <br>
      I&#39;m willing to be persuaded that we&#39;re wrong, though.=A0 It m=
ay well
      be that our intended interpretation causes problems that we did
      not foresee.=A0 <br><span class=3D"HOEnZb"><font color=3D"#888888">
      <br>
      - Jim<br></font></span>
      P.S. Everyone who has worked with the XPath data model has had
      problems with it.=A0 <br>
      <br>
      <br>
      <br>
    </a><div><div class=3D"h5">
    <div>On 2/9/2015 4:20 PM, Ate Douma wrote:<br>
    </div>
    <blockquote type=3D"cite">Hi
      Zjnue,
      <br>
      <br>
      <br>
      On 2015-02-09 19:28, Zjnue Brzavi wrote:
      <br>
      <blockquote type=3D"cite">Hi Ate,
        <br>
        <br>
        =A0=A0=A0=A0=A0=A0 &lt;datamodel&gt;
        <br>
        =A0=A0=A0=A0=A0=A0=A0=A0 &lt;data id=3D&quot;Var1&quot; expr=3D&quo=
t;0&quot;/&gt;
        <br>
        =A0=A0=A0=A0=A0=A0=A0=A0 &lt;data id=3D&quot;Var2&quot;/&gt;
        <br>
        =A0=A0=A0=A0=A0=A0=A0=A0 &lt;data id=3D&quot;Var3&quot;&gt;
        <br>
        =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 &lt;node xmlns=3D&quot;&quot;&gt;1&l=
t;/node&gt;&lt;node
        xmlns=3D&quot;&quot;&gt;2&lt;/node&gt;&lt;node xmlns=3D&quot;&quot;=
&gt;3&lt;/node&gt;
        <br>
        =A0=A0=A0=A0=A0=A0=A0=A0 &lt;/data&gt;
        <br>
        =A0=A0=A0=A0=A0=A0=A0=A0 &lt;data id=3D&quot;Var4&quot; expr=3D&quo=
t;1&quot;/&gt;
        <br>
        =A0=A0=A0=A0=A0=A0 &lt;/datamodel&gt;
        <br>
        <br>
        [..]
        <br>
        <br>
        =A0=A0=A0 The &quot;Var2/text()&quot; xpath expressions in the if c=
ondition
        check and the
        <br>
        =A0=A0=A0 assignment value expression above are not valid/usable in
        this context.
        <br>
        <br>
        =A0=A0=A0 The foreach element will assign each of the Var3
        &lt;node&gt;x&lt;/node&gt; children to
        <br>
        =A0=A0=A0 the Var2 variable, and the Var2 variable (its data node)
        thus will contains
        <br>
        =A0=A0=A0 no (direct) text node children, only a (single) &quot;nod=
e&quot;
        child.
        <br>
        <br>
        =A0=A0=A0 To access the actual text value of that &quot;node&quot; =
child, the
        expression must
        <br>
        =A0=A0=A0 be: &quot;$Var2/*/text()&quot; or if desired &quot;$Var2/=
node[1]/text()&quot;.
        <br>
        <br>
        <br>
        This is something I&#39;ve implemented also, and on this rare
        occasion I have to
        <br>
        disagree with the suggestion.
        <br>
        <br>
        Let&#39;s take this SO post as context:
        <br>
<a href=3D"http://stackoverflow.com/questions/11744465/xpath-difference-bet=
ween-node-and-text" target=3D"_blank">http://stackoverflow.com/questions/11=
744465/xpath-difference-between-node-and-text</a>
        <br>
        <br>
        Now back to the example you&#39;ve stated.
        <br>
        Var3 evaluates to an XMLList, which has this simplified
        structure:
        <br>
        <br>
        element node (name=3D&quot;node&quot;)
        <br>
        =A0=A0=A0=A0 text node (value=3D&quot;1&quot;)
        <br>
        element node (name=3D&quot;node&quot;)
        <br>
        =A0=A0=A0=A0 text node (value=3D&quot;2&quot;)
        <br>
        element node (name=3D&quot;node&quot;)
        <br>
        =A0=A0=A0=A0 text node (value=3D&quot;3&quot;)
        <br>
        <br>
        Now, in the foreach structure, as we iterate through this list,
        we assign a
        <br>
        reference to the next element node to Var2.
        <br>
        In turn, $Var2/text() evaluates to 1, 2 and 3 as we expect.
        <br>
        <br>
        My guess is that your implementation creates a new XML instance
        when assigning
        <br>
        values to Var2, giving it values such as:
        <br>
        <br>
        root node
        <br>
        =A0=A0=A0=A0 element node (name=3D&quot;node&quot;)
        <br>
        =A0=A0=A0=A0=A0=A0=A0=A0 text node (value=3D&quot;1&quot;)
        <br>
        <br>
        root node
        <br>
        =A0=A0=A0=A0 element node (name=3D&quot;node&quot;)
        <br>
        =A0=A0=A0=A0=A0=A0=A0=A0 text node (value=3D&quot;2&quot;)
        <br>
        <br>
        and so on, thereby requiring the extra axis specifier as you
        suggested:
        <br>
        $Var2/*/text()=A0=A0 OR=A0 $Var2/node[1]/text()
        <br>
        <br>
        However, as we are dealing with a complex type, I believe it is
        wrong to create
        <br>
        new instances and that we should use references to the existing
        nodes, making
        <br>
        the tests valid as they are currently specified.
        <br>
        <br>
        In my implementation, I have a normalized foreach routine for
        the different
        <br>
        datamodels:
        <br>
<a href=3D"https://github.com/zjnue/hscxml/blob/master/src/hsm/scxml/Interp=
.hx#L935-L972" target=3D"_blank">https://github.com/zjnue/hscxml/blob/maste=
r/src/hsm/scxml/Interp.hx#L935-L972</a>
        <br>
        <br>
        This works well for the tests mentioned, when I feed it with an
        array containing
        <br>
        references to the different nodes in the XMLList, formed here:
        <br>
<a href=3D"https://github.com/zjnue/hscxml/blob/master/src/hsm/scxml/Model.=
hx#L354-L366" target=3D"_blank">https://github.com/zjnue/hscxml/blob/master=
/src/hsm/scxml/Model.hx#L354-L366</a>
        <br>
        <br>
        Do you agree?
        <br>
      </blockquote>
      <br>
      I agree such a solution was what I also implemented initially.
      <br>
      <br>
      However I changed my view on it and now implemented an actual item
      copy assignment to the variable &lt;data&gt; node, and even create
      such a &lt;data&gt; node first if it doesn&#39;t yet exist (as
      required and tested by tests 150 and 151).
      <br>
      <br>
      The reason I changed my implementation is that the wording in the
      specification and the tests made me conclude that the intent is
      that XPath variables (in SCXML) always (must) refer to an actual
      &lt;data&gt; node with an id equal to the variable name.
      <br>
      <br>
      In the solution you implemented the XPath variable *initially*
      refers to such a &lt;data&gt; node, but then loses its
      binding/reference to a datamodel &lt;data&gt; node and becomes a
      &#39;transient&#39; reference to the intermediate array items.
      <br>
      <br>
      Although I&#39;d also rather and more optimally would like to use the
      XPath variables as transient pointers, the spec wording and IR
      tests don&#39;t seem to agree with that.
      <br>
      Your implementation maybe passes each individual tests, but if
      rules and semantics checked in one test should also apply in other
      tests, then IMO your solution no longer is or would be valid.
      <br>
      <br>
      Note for example that such transient XPath variable no longer will
      agree to an XPath test like &quot;local-name($Var2)=3D=3D&#39;data&#3=
9; and
      &#39;$Var2@id=3D&#39;Var2&#39;&quot;, something test 463 is testing. =
Of course not in
      the context of a &lt;foreach&gt;, but I assume(d?) such XPath
      variable conditions should always be true.
      <br>
      <br>
      One thing which seems to be required anyway is that if a
      &lt;foreach&gt; item or index doesn&#39;t exist yet, at least a Node
      element must be created to hold the variable data, as for example
      is checked by tests 150 and 151.
      <br>
      <br>
      Note also that in test 151 the index variable, which just &#39;holds&=
#39;
      a number, still requires creating a Node variable because of the
      final test condition &quot;&quot;$Var5/* or $Var5/text()&quot;.
      <br>
      A &#39;normal&#39; XPath variable perfectly well can point to just a
      number value, however the SCXML spec (and/or tests) require even
      for such variables an actual (data) node element.
      <br>
      <br>
      But, maybe I&#39;ve been assuming and interpreting too much into
      this...
      <br>
      Trying to get the xpath datamodel implementation working properly,
      and as intended, has been (and still is) quite a challenge so say
      the least.
      <br>
      <br>
      Maybe Jim can chime in and help clarify what the actual or
      intended requirements concerning XPath variables are.
      <br>
      <br>
      Thanks, Ate
      <br>
      <br>
      <blockquote type=3D"cite">
        <br>
        Best regards,
        <br>
        Zjnue
        <br>
        <br>
      </blockquote>
      <br>
      <br>
    </blockquote>
    <br>
  </div></div></div>

</blockquote></div><br></div>

--047d7bdc87a231d8a9050eaf6c98--