如何将纬度和经度的值替换为一个元素值?
How to replace values of latitude and longitude into one element value?
xml file looks like this
如何做到这一点?
您需要将纬度和经度的值替换为一个元素值。
例如:
现有一个
<Longitude>-0.30365</Longitude>
<Latitude>51.61965</Latitude>
新一期:
<cordinate-point>-0.30365,51.619165<cordinate-point>
您可以使用 xdmp:node-insert-before()
and 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)
)
您可以使用 xdmp:xslt-eval()
with a locally evaluated stylesheet or xdmp:xslt-invoke()
with an installed XSLT, and then replace the existing document with the result of the transform using xdmp:node-replace()
:
使用 XSLT 转换文档
declare variable $XSLT :=
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="2.0">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<!--replace the Latitude element with a cordinate-point element -->
<xsl:template match="Latitude">
<cordinate-point>
<xsl:value-of select="., ../Longitude" separator=","/>
</cordinate-point>
</xsl:template>
<!--drop the Longitude element -->
<xsl:template match="Longitude"/>
</xsl:stylesheet>;
let $doc := fn:doc("/uri/to/your/doc.xml")
return
xdmp:node-replace($doc, xdmp:xslt-eval($XSLT, $doc))
xml file looks like this 如何做到这一点? 您需要将纬度和经度的值替换为一个元素值。
例如: 现有一个
<Longitude>-0.30365</Longitude>
<Latitude>51.61965</Latitude>
新一期:
<cordinate-point>-0.30365,51.619165<cordinate-point>
您可以使用 xdmp:node-insert-before()
and 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)
)
您可以使用 xdmp:xslt-eval()
with a locally evaluated stylesheet or xdmp:xslt-invoke()
with an installed XSLT, and then replace the existing document with the result of the transform using xdmp:node-replace()
:
declare variable $XSLT :=
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="2.0">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<!--replace the Latitude element with a cordinate-point element -->
<xsl:template match="Latitude">
<cordinate-point>
<xsl:value-of select="., ../Longitude" separator=","/>
</cordinate-point>
</xsl:template>
<!--drop the Longitude element -->
<xsl:template match="Longitude"/>
</xsl:stylesheet>;
let $doc := fn:doc("/uri/to/your/doc.xml")
return
xdmp:node-replace($doc, xdmp:xslt-eval($XSLT, $doc))