首页 > 解决方案 > 如何将纬度和经度值替换为一个元素值?

问题描述

xml 文件看起来像这样 如何实现这一点?您需要将纬度和经度的值替换为一个元素值。

例如:现有的

<Longitude>-0.30365</Longitude>
<Latitude>51.61965</Latitude>

新的一个 : <cordinate-point>-0.30365,51.619165<cordinate-point>

标签: xquerymarklogic

解决方案


您可以使用xdmp:node-insert-before()xdmp:node-delete()功能:

let $doc :- fn:doc("/uri/of/your/doc.xml")
let $long := $doc/root/Longitude
let $lat := $doc/root/Latitude
(: construct an element with text() value of the Longitude and Latitude elements :)
let $point := <cordinate-point>{string-join(($lat,$long), ",")}</cordinate-point>
return
  (
    (: insert a new coordinate-point element before the Longitude element :)
    xdmp:node-insert-before($long, $point),
    (: Remove the Longitude element :)
    xdmp:node-delete($long),
    (: Remove the Latitude element :)
    xdmp:node-delete($lat)
  )

推荐阅读