<div dir="ltr"><br><div class="gmail_extra"><br><br><div class="gmail_quote">On Mon, Jan 6, 2014 at 11:04 PM, David Lutterkort <span dir="ltr"><<a href="mailto:lutter@watzmann.net" target="_blank">lutter@watzmann.net</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr">Hi Raphael,<br><div class="gmail_extra"><br>
<br><div class="gmail_quote"><div class="im">On Fri, Dec 20, 2013 at 2:24 PM, Raphaël Pinson <span dir="ltr"><<a href="mailto:raphael.pinson@camptocamp.com" target="_blank">raphael.pinson@camptocamp.com</a>></span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div dir="ltr"><span style="font-family:arial,sans-serif;font-size:13px">Hello,</span><div style="font-family:arial,sans-serif;font-size:13px">

<br></div><div style="font-family:arial,sans-serif;font-size:13px"><br></div><div style="font-family:arial,sans-serif;font-size:13px">
There's regularly people asking how to write idempotent set expressions. With labeled nodes, we have the usual trick:<br></div><div style="font-family:arial,sans-serif;font-size:13px"><br></div><div style="font-family:arial,sans-serif;font-size:13px">


    set foo[.='bar'] 'bar'</div><div style="font-family:arial,sans-serif;font-size:13px"><br></div><div style="font-family:arial,sans-serif;font-size:13px">which creates the 'foo' node with the 'bar' value if it doesn't exist.</div>

</div></blockquote><div><br></div></div><div>Yes, I agree with both - that it's not wel supported right now, and that it is needed. The underlying problem is that there's no good way to infer from a path expression where the newly created node  should go in case the path expression doesn't match.<br>

<br></div><div>Rather than put something in the XPath language, I think it would be cleaner to do this explicitly in a dedicated command. I can think of a few ways to do that. The simplest would be a aug_set_or_create(expr, path, value) that goes something like this:<br>

<br><div style="margin-left:40px">if aug_match(expr) == 1<br></div><div style="margin-left:40px">  aug_set(expr, value)<br></div><div style="margin-left:40px">elsif aug_match(expr) == 0<br></div><div style="margin-left:40px">

  aug_set(path, value)<br></div><div style="margin-left:40px">else<br></div><div style="margin-left:40px">  complain<br></div><div style="margin-left:40px">end<br></div></div></div></div></div></blockquote><div><br></div>
<div><br></div><div>Come to think of it, one very useful call for idempotent set commands is defnode, which I've been using extensively lately, such as in this situation: <a href="http://stackoverflow.com/a/21342882/232250">http://stackoverflow.com/a/21342882/232250</a></div>
<div><br></div><div>Defnode is very useful in that it sets a variable pointing to the newly create node (or to the nodeset already matching). The thing that's missing in defnode is precisely this default label thing, especially when dealing with seq entries.</div>
<div><br></div><div>So maybe rather than adding an aug_set_or_create() call, we could have a defnode_default() call, which would allow to pass a default path to defnode, the advantage being that we would always get a variable pointing to the resulting path.</div>
<div><br></div></div><div><br></div>-- <br><div dir="ltr">Raphaël Pinson<div>Infrastructure Developer & Trainer</div><div>+33 479 26 57 93<div>+33 781 90 00 79</div><div><br></div><div>Camptocamp France<br>
Savoie Technolac<br>
BP 352<br>
48, avenue du Lac du Bourget<br>
73372 Le Bourget du Lac, Cedex<br>
<a href="http://www.camptocamp.com" target="_blank">www.camptocamp.com</a><br>
</div></div></div>
</div></div>