3

私はcsvファイルを持っています。mlcp を使用してこれらのデータを MarkLogic にインポートし、MarkLogic で xml ファイルを作成しました。

今csvで、列の1つにランダムに「6/29/2013 5:00:00 PM」という形式があります。xquery とおそらく node-replace を変換関数として使用して、この日付を MarkLogic のデフォルトの日付形式として「2013-06-29」などの別の形式に変換するにはどうすればよいですか?

どんな助けでも大歓迎です...


transform.xqy を作成し、MLogic のモジュールにインストールしました。「xdmp:node-replace」を使用して、日付を期待される形式に置き換えることを考えています。または、列ごとに csv 列を調べて (方法は?)、「castable as xs:dateTime」を使用して日付値を決定する必要があります。それでも、コンテンツの値/uriを出力するだけでも、常にエラーが発生します。

xquery version "1.0-ml";
module namespace example = "http://test.com/example";

(: If the input document is XML, insert @NEWATTR, with the value
 : specified in the input parameter. If the input document is not
 : XML, leave it as-is.
 :)
declare function example:transform(
  $content as map:map,
  $context as map:map
) as map:map*
{
  let $the-doc-uri := map:get($content, "uri")
  let $the-doc := map:get($content, "value")
  return
    trace($the-doc, 'The value of doc is: ')
};
4

2 に答える 2

0

ついにやった。

問題は、 mem:node-replaceを使用する必要があるということです。これはオンザフライでメモリ上にあるためです。xdmp :node-replaceは、データがすでに MarkLogic にある場合です。

残りは期待どおりです。必要に応じて、 format-datexdmp:parse-dateTimeを使用して日付形式を取得する必要があります。

ここにいくつかのスニペットがあります

xquery version "1.0-ml";
module namespace ns_transform = "this_is_my_namespace";
import module namespace mem = "http://xqdev.com/in-mem-update" at "/MarkLogic/appservices/utils/in-mem-update.xqy";

declare variable $ns := "this_is_my_namespace";

declare function ns_transform:transform(
  $content as map:map,
  $context as map:map
) as map:map*
{  

    let $doc := map:get($content, "value")

    let $format_in := "[M]/[D]/[Y0001] [h01]:[m01]:[s01] [P]"
    let $format_out := "[Y0001]-[M01]-[D01]"

    let $old_date := $doc/*:root_doc/*:date/text()
    let $new_date :=  format-date(xs:date(xdmp:parse-dateTime($format_in, $old_date)), $format_out)

    let $new_doc := mem:node-replace($doc/*:root_doc/*:date,element {fn:QName($ns, "date")}{$new_date})
    let $_ := map:put($content, "value", $new_doc)

    return $content  
};
于 2016-06-08T04:00:30.853 に答える