我使用 stylus studio(带有 DATA DIRECT)/xQuery 将两个 xmls 文件合并为一个(文件先从 CSV 转换为 xml,然后再加入)。首先读取客户(标题)数据,然后为每个客户读取匹配交易数据。(使用循环)交易数据也按交易日期(年份)分组。这是通过使用 distinct 函数完成的。交易数据文件很大,处理速度很慢。我正在寻找提高性能的方法。任何帮助。建议很受欢迎。下面是使用的代码。谢谢。
(:options:)
declare option ddtek:xml-streaming "yes";
declare option ddtek:serialize "encoding=UTF-8,
omit-xml-declaration=no, indent=yes";
(:external variables:)
declare variable $esa-h-converter as xs:string external;
declare variable $esa-t-converter as xs:string external;
declare variable $input-h-data-path as xs:string external;
declare variable $input-t-data-path as xs:string external;
(:main:)
<ROOT_NODE>
{
let $heads := doc(fn:concat(
"converter:",
$esa-h-converter,
"?file:///",
$input-h-data-path))
/DATA_ROOT/CUSTOMER
for $record at $primaryKey in $heads
return
<TEMPLATE>
<CUSTOMER>
<RECORD_COUNT>{ $primaryKey }</RECORD_COUNT>
<HD_REGION>{ $record/HD_REGION/text() }</HD_REGION>
<HD_CONT>{ $record/HD_CONT/text() }</HD_CONT>
<HD_FRDATE>{ $record/HD_FRDATE/text() }</HD_FRDATE>
<HD_TODATE>{ $record/HD_TODATE/text() }</HD_TODATE>
<HD_CUSNAME>{ $record/HD_CUSNAME/text() }</HD_CUSNAME>
<HD_ADDR1>{ $record/HD_ADDR1/text() }</HD_ADDR1>
<HD_ADDR2>{ $record/HD_ADDR2/text() }</HD_ADDR2>
<HD_ADDR3>{ $record/HD_ADDR3/text() }</HD_ADDR3>
<HD_ADDR4>{ $record/HD_ADDR4/text() }</HD_ADDR4>
<HD_STATE>{ $record/HD_STATE/text() }</HD_STATE>
<HD_SUBTOWN>{ $record/HD_SUBTOWN/text() }</HD_SUBTOWN>
<HD_PCODE>{ $record/HD_PCODE/text() }</HD_PCODE>
{
let $my-transactions :=
doc(fn:concat("converter:",
$esa-t-converter,
"?file:///",
$input-t-data-path))
/DATA_ROOT
/TRANSACTION
[TR_CONT eq $record/HD_CONT
and TR_REGION eq $record/HD_REGION]
let $years := fn:distinct-values(
$my-transactions
/fn:substring(TR_DATE/text(), 1, 4))
for $period in $years
return
<PERIOD>
<RECORD_COUNT>{ $primaryKey }</RECORD_COUNT>
<YEAR>{ $period }</YEAR>
{
$my-transactions
[fn:substring(TR_DATE/text(), 1, 4) = $period]
}
</PERIOD>
}
</CUSTOMER>
</TEMPLATE>
}
</ROOT_NODE>