{"id":388,"date":"2008-11-28T22:47:47","date_gmt":"2008-11-29T05:47:47","guid":{"rendered":"https:\/\/dubinko.info\/blog\/?p=388"},"modified":"2008-11-28T22:47:47","modified_gmt":"2008-11-29T05:47:47","slug":"fun-with-xdmpvalue","status":"publish","type":"post","link":"https:\/\/dubinko.info\/blog\/2008\/11\/fun-with-xdmpvalue\/","title":{"rendered":"Fun with xdmp:value()"},"content":{"rendered":"<p>Lately I&#8217;ve been playing with some more advanced XQuery. One thing nearly every XQuery engine supports is some kind of <code>eval()<\/code> function. MarkLogic has several, but my <a href=\"http:\/\/developer.marklogic.com\/pubs\/4.0\/apidocs\/Extension.html#xdmp:value\">favorite<\/a> is xdmp:eval. It&#8217;s lightweight because it reuses the entire calling context, so for instance you can write <code>let $v := 5 return xdmp:value(\"$v\")<\/code>. Not too useful, but if the expression passed in comes from a variable, it gets interesting.<\/p>\n<p>Now, quite a few standards based on XPath depend on the context node being set to some particular node. This turns out to be easy too, using the path operator: <code>$context\/xdmp:value($expr)<\/code>. According to the definition of the XPath path operator, the expression to the right is evaluated with the results of the expression on the left setting the context node.<\/p>\n<p>OK, how about setting the context size and position? More difficult, but one could use a sequence on the left-hand side of the path operator, with the desired <code>$context<\/code> node in somewhere in the middle. Then <code>last()<\/code> will return the length of the sequence, and <code>position()<\/code> will return, well, the position of <code>$context<\/code> in the sequence. But it&#8217;s kind of hacky to manufacture a bunch of temporary nodes, only to throw them away in the next step of the path.<\/p>\n<p>I&#8217;m curious if anyone else has done something similar. Comments? -m<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Lately I&#8217;ve been playing with some more advanced XQuery. One thing nearly every XQuery engine supports is some kind of eval() function. MarkLogic has several, but my favorite is xdmp:eval. It&#8217;s lightweight because it reuses the entire calling context, so for instance you can write let $v := 5 return xdmp:value(&#8220;$v&#8221;). Not too useful, but&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[27,113,9,124],"tags":[525],"class_list":["post-388","post","type-post","status-publish","format-standard","hentry","category-languages","category-mark-logic","category-standards","category-xquery-standards","tag-marklogic-eval-xquery-higherorder-context-xpath-sequence"],"aioseo_notices":[],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p8eo8l-6g","_links":{"self":[{"href":"https:\/\/dubinko.info\/blog\/wp-json\/wp\/v2\/posts\/388","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/dubinko.info\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/dubinko.info\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/dubinko.info\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/dubinko.info\/blog\/wp-json\/wp\/v2\/comments?post=388"}],"version-history":[{"count":0,"href":"https:\/\/dubinko.info\/blog\/wp-json\/wp\/v2\/posts\/388\/revisions"}],"wp:attachment":[{"href":"https:\/\/dubinko.info\/blog\/wp-json\/wp\/v2\/media?parent=388"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/dubinko.info\/blog\/wp-json\/wp\/v2\/categories?post=388"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/dubinko.info\/blog\/wp-json\/wp\/v2\/tags?post=388"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}