Replace Me

XQuery fn: replace not as expected

I have an Excel XML worksheet that contains

<Cell ss:StyleID="s127"><Data ss:Type="String">Replace Me</Data></Cell>

I want to replace @ A01-Replace with another line. I use the XQuery replacement function as follows:

let $excel := doc("document.xml")

let $test := "another string"

return replace($excel, "Replace Me", $test)

Before calling replace, the $ excel variable is valid for XML after output. However, when I print $ excel after calling the replace function, all the XML tags have been removed, and $ excel is a string with the contents of the cells as values. I would like to save XML tags there.

I expect

<Cell ss:StyleID="s127"><Data ss:Type="String">another string</Data></Cell>

However i get

another string

All XML tags are deleted.

Any ideas?

0
source share
1 answer

fn:replace - A simple string manipulation function from XQuery.

This function works with strings, not node () * types data-type.

let $replaced-str := fn:replace( $excel/Data/text(), "Replace Me", $test)

.

XML-, xdmp:node-replace, MarkLogic XmlDatabase.

XQuery/Xml/Memory node-replace, , XPath node. MarkLogic-commons.

0

Source: https://habr.com/ru/post/1746929/


All Articles