tags:

views:

119

answers:

1

I have an Excel worksheet in XML format which contains

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

I want to replace @A01-Replace with a different string. I'm using the XQuery's replace function like so:

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

let $test := "another string"

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

Before calling replace, the variable $excel is valid XML upon output. However, when I output $excel after I call the replace function, all of the XML tags have been stripped, and $excel is a string with the content of the cells as its values. I would like to keep the XML tags there.

What I expect is

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

However, I get

another string

All the XML tags are stripped out.

Any ideas?

A: 

fn:replace is a simple String Manipulation Function from XQuery.

function works with in a String and not node()* types data-type.

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

if you wanted to work with a Xml document then you need to use

xdmp:node-replace type function which is specific to MarkLogic XmlDatabase.

if you want simple XQuery/Xml/Memory based node-replace then you can write a simple recursive replace method which accepts an XPath and re-creates new node. or check out the this MarkLogic-commons example

Refer : http://github.com/marklogic/commons/blob/master/memupdate/in-mem-update.xqy

kadalamittai