Mark, it looks like the problem is that the two parameters to xdmp:node-replace don't match up -- $t is an element node, the second parameter is a text node.
I'm not positive, but I think you can use the xh:CURRENTDATE text node as the first parameter: declare namespace xh="http://newnamespace/"; for $t in (/xh:TABLE)/xh:CURRENTDATE let $tt := $t/string let $parts := fn:tokenize($t, " ") let $datepart := fn:tokenize($parts[1], "/") let $timestamp := fn:concat($datepart[3],"-", $datepart[1],"-",$datepart[2],"T",$parts[2]) return xdmp:node-replace($t/text(), text{fn:concat("<CURRENTDATE>",$timestamp,"</CURRENTDATE>")} ) … assuming that there is, in fact, just one text node under the xh:CURRENTDATE element. The other thing you could do is specify the full element in the second parameter, complete with namespace: return xdmp:node-replace($t, <xh:CURRENTDATE>{$timestamp}</xh:CURRENTDATE>) The assumption here is that xh:CURRENTDATE has no other children, but that seems to be the case. -- Dave Cassel<http://davidcassel.net>, @dmcassel<https://twitter.com/dmcassel> Developer Community Manager MarkLogic Corporation<http://www.marklogic.com/> Data Innovation Summit<http://fedscoop.com/events/datainnovationsummit/2015/> May 7th in DC From: Mark Shanks <[email protected]<mailto:[email protected]>> Reply-To: MarkLogic Developer Discussion <[email protected]<mailto:[email protected]>> Date: Tuesday, April 21, 2015 at 4:37 PM To: "[email protected]<mailto:[email protected]>" <[email protected]<mailto:[email protected]>> Subject: [MarkLogic Dev General] Converting date format using xquery? Hi, I have some data ingested into Marklogic, but found that marklogic cannot interpret dates in the form sql typically outputs, e.g., 03/17/2014 09:55:22. Instead, it should be in the xml form 2014-04-30T05:30:41. I wrote the following xquery to convert all of the dates in the referenced column, but it puts the entry in as a node but marklogic doesn't recognize it as a node. What is going wrong? declare namespace xh="http://newnamespace/"; for $t in (/xh:TABLE)/xh:CURRENTDATE let $tt := $t/string let $parts := fn:tokenize($t, " ") let $datepart := fn:tokenize($parts[1], "/") let $timestamp := fn:concat($datepart[3],"-", $datepart[1],"-",$datepart[2],"T",$parts[2]) return xdmp:node-replace($t, text{fn:concat("<CURRENTDATE>",$timestamp,"</CURRENTDATE>")} ) Note that I tried the element statement in the node-replace, but this would rewrite the node with an empty namespace. It wasn't clear to me how to reference the correct namespace. Is there also a general function to convert all dates in marklogic into xml format? Thanks.
_______________________________________________ General mailing list [email protected] Manage your subscription at: http://developer.marklogic.com/mailman/listinfo/general
