以下の例に似た構造のXMLがあります。これをCSVにエクスポートするXLogicをMarkLogicで作成しました。CSVファイルにエクスポートしたときのMarkLogic結果の書式設定方法
私が助けが必要なのは、CSVファイルを開いたときに、出力をすべて1にするのではなく、グループ化して話したいということです。
は、私はDataTimeとソース要素の値のすべて出力したいのは、以下のサンプルのために言ってみましょう。このような自分の列の値があります。
2012-02-15T00:58:26 a
2012-02-15T00:58:26 b
2012-02-15T00:58:26 c
は、どのように私はそれについて行くだろうか?
参照点や援助を歓迎しますか?前もって感謝します。
ここではサンプルのXMLです:
<Document xmlns="http://fakeexample.org/schemas">
<Information>
<ItemId>1f28cb0c2c4f4eb7b13c4abf998e391e</ItemId>
<MediaType>Text</MediaType>
<DocDateTime>2012-02-15T00:58:26</DocDateTime>
</Information>
<FilingData>
<DateTime>2012-02-15T00:58:26</DateTime>
<Source>a</Source>
</FilingData>
<FilingData>
<DateTime>2012-02-15T00:58:27</DateTime>
<Source>b</Source>
</FilingData>
<FilingData>
<DateTime>2012-02-15T00:58:28</DateTime>
<Source>c</Source>
</FilingData>
</Document>
ここではサンプルのXQueryだ:
xquery version "1.0-ml";
declare default function namespace "http://www.w3.org/2005/xpath-functions";
declare namespace xdmp="http://marklogic.com/xdmp";
declare namespace exam="http://fakeexample.org/schemas";
declare function local:getDocument($url)
{
let $response := xdmp:document-get($url,
<options xmlns="xdmp:document-get">
<repair>full</repair>
<format>xml</format>
</options>)
return $response
};
xdmp:set-response-content-type("text/csv"),
xdmp:add-response-header(
"Content-disposition",
fn:concat("attachment;filename=", "output", fn:current-time(), ".csv")
),
(
let $q := cts:element-value-query(xs:QName("exam:ItemId"), ("1f28cb0c2c4f4eb7b13c4abf998e391e"))
let $results := cts:search(fn:doc(), $q)
for $result in $results
return fn:string-join((xs:string($result//exam:DateTime),
xs:string($result//exam:Source)
), ",")
)
文字列、改行、および引用符をコンテンツからエスケープすることについて心配する必要はありませんか? (Fwiw、私はそれが再利用できるように逃げた図書館を見たいです:) –
@ eric-bloch与えられたXMLでは、いいえ。 ;-) – grtjn
返信いただきありがとうございます。残念ながら、依然としてdate1、date2、date3、source1、source2、source3のように1行にわたって結果を書きました。マップの使い方を調べる。私はそれが動作するようになる場合、更新を投稿します。 – zrdunlap