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

Zjnue Brzavi <[email protected]> Mon, 9 Feb 2015 19:28:44 +0100
Newsgroups gmane.comp.web.voice
Message-ID <CABmmmmz7PFJCuJ898hpm4d91yGCP5-8D5yJP0hf2wvs2xHdMTg@mail.gmail.com>
--089e0122f1b6c25758050eabf09f
Content-Type: text/plain; charset=ISO-8859-1

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?

Best regards,
Zjnue

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

<div dir=3D"ltr">Hi Ate,<br><div><div class=3D"gmail_extra"><div class=3D"g=
mail_quote"><div>=A0</div><blockquote class=3D"gmail_quote" style=3D"margin=
:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"=
>
=A0 &lt;datamodel&gt;<br>
=A0 =A0 &lt;data id=3D&quot;Var1&quot; expr=3D&quot;0&quot;/&gt;<br>
=A0 =A0 &lt;data id=3D&quot;Var2&quot;/&gt;<br>
=A0 =A0 &lt;data id=3D&quot;Var3&quot;&gt;<br>
=A0 =A0 =A0 &lt;node xmlns=3D&quot;&quot;&gt;1&lt;/node&gt;&lt;node xmlns=
=3D&quot;&quot;&gt;2&lt;/node&gt;&lt;node xmlns=3D&quot;&quot;&gt;3&lt;/nod=
e&gt;<br>
=A0 =A0 &lt;/data&gt;<br>
=A0 =A0 &lt;data id=3D&quot;Var4&quot; expr=3D&quot;1&quot;/&gt;<br>
=A0 &lt;/datamodel&gt;<br></blockquote><div>=A0</div><div>[..]<br>=A0<br></=
div><blockquote class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;bor=
der-left:1px solid rgb(204,204,204);padding-left:1ex">
The &quot;Var2/text()&quot; xpath expressions in the if condition check and=
 the assignment value expression above are not valid/usable in this context=
.<br>
<br>
The foreach element will assign each of the Var3 &lt;node&gt;x&lt;/node&gt;=
 children to the Var2 variable, and the Var2 variable (its data node) thus =
will contains no (direct) text node children, only a (single) &quot;node&qu=
ot; child.<br>
<br>
To access the actual text value of that &quot;node&quot; child, the express=
ion must be: &quot;$Var2/*/text()&quot; or if desired &quot;$Var2/node[1]/t=
ext()&quot;.<br></blockquote><br></div><div class=3D"gmail_quote">This is s=
omething I&#39;ve implemented also, and on this rare occasion I have to dis=
agree with the suggestion.<br><br></div><div class=3D"gmail_quote">Let&#39;=
s take this SO post as context:<br><a href=3D"http://stackoverflow.com/ques=
tions/11744465/xpath-difference-between-node-and-text">http://stackoverflow=
.com/questions/11744465/xpath-difference-between-node-and-text</a><br><br><=
/div><div class=3D"gmail_quote">Now back to the example you&#39;ve stated.<=
br></div><div class=3D"gmail_quote">Var3 evaluates to an XMLList, which has=
 this simplified structure:<br><br>element node (name=3D&quot;node&quot;)<b=
r>=A0=A0=A0 text node (value=3D&quot;1&quot;)<br>element node (name=3D&quot=
;node&quot;)<br>=A0=A0=A0 text node (value=3D&quot;2&quot;)<br>element node=
 (name=3D&quot;node&quot;)<br>=A0=A0=A0 text node (value=3D&quot;3&quot;)<b=
r><br></div><div class=3D"gmail_quote">Now, in the foreach structure, as we=
 iterate through this list, we assign a reference to the next element node =
to Var2.<br></div><div class=3D"gmail_quote">In turn, $Var2/text() evaluate=
s to 1, 2 and 3 as we expect.<br><br></div><div class=3D"gmail_quote">My gu=
ess is that your implementation creates a new XML instance when assigning v=
alues to Var2, giving it values such as:<br><br>root node<br>=A0=A0=A0 elem=
ent node (name=3D&quot;node&quot;)<br>=A0=A0=A0=A0=A0=A0=A0 text node (valu=
e=3D&quot;1&quot;)<br><br>root node<br>=A0=A0=A0 element node (name=3D&quot=
;node&quot;)<br>=A0=A0=A0=A0=A0=A0=A0 text node (value=3D&quot;2&quot;)<br>=
<br></div><div class=3D"gmail_quote">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></div><div class=3D"gmail_quote">However, as we are dealin=
g with a complex type, I believe it is wrong to create new instances and th=
at we should use references to the existing nodes, making the tests valid a=
s they are currently specified.<br><br></div><div class=3D"gmail_quote">In =
my implementation, I have a normalized foreach routine for the different da=
tamodels:<br><a href=3D"https://github.com/zjnue/hscxml/blob/master/src/hsm=
/scxml/Interp.hx#L935-L972">https://github.com/zjnue/hscxml/blob/master/src=
/hsm/scxml/Interp.hx#L935-L972</a><br><br></div><div class=3D"gmail_quote">=
This works well for the tests mentioned, when I feed it with an array conta=
ining 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">https://github.com/zjnue/hscxml/blob/master/src/hsm/scxml/Model.=
hx#L354-L366</a><br><br></div><div class=3D"gmail_quote">Do you agree?<br><=
/div><div class=3D"gmail_quote"><br></div><div class=3D"gmail_quote">Best r=
egards,<br></div><div class=3D"gmail_quote">Zjnue<br></div><div class=3D"gm=
ail_quote"><br></div></div></div></div>

--089e0122f1b6c25758050eabf09f--