我需要获取一个XML文件并创建一个新的输出文件。 在创建输出文件的过程中,我需要按物料总计数量
这是我的输入文件:-
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<data-set xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<record>
<MATERIAL>Material1</MATERIAL>
<SALES_DIST>FS</SALES_DIST>
<REGION>North</REGION>
<FIELDNM001>EA</FIELDNM001>
<MONTH>2020-01-01</MONTH>
<FIELDNM002>1</FIELDNM002>
</record>
<record>
<MATERIAL>Material1</MATERIAL>
<SALES_DIST>FS</SALES_DIST>
<REGION>North</REGION>
<FIELDNM001>EA</FIELDNM001>
<MONTH>2020-01-01</MONTH>
<FIELDNM002>1</FIELDNM002>
</record>
</data-set>
我最后需要的是一个像这样的文件:-
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<data-set xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<record>
<MATERIAL>Material1</MATERIAL>
<SALES_DIST>FS</SALES_DIST>
<REGION>North</REGION>
<FIELDNM001>EA</FIELDNM001>
<MONTH>2020-01-01</MONTH>
<FIELDNM002>2</FIELDNM002>
</record>
</data-set>
关于实现此目标的xslt文档的任何想法?
非常感谢。
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<data-set xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<record>
<MATERIAL>Material1</MATERIAL>
<SALES_DIST>FS</SALES_DIST>
<REGION>North</REGION>
<FIELDNM001>EA</FIELDNM001>
<MONTH>2020-01-01</MONTH>
<FIELDNM002>2</FIELDNM002>
</record>
</data-set>
答案 0 :(得分:-1)
从this reply开始,以下在Linux上使用xsltproc对我有用:
<!DOCTYPE html>
<html>
<head>
<style>
.as-console-wrapper {
width: 350px;
min-height: 100%;
margin-left: 45%;
}
.as-console-row.as-console-row::after {
content: '';
padding: 0;
margin: 0;
border: 0;
width: 0;
}
</style>
</head>
<body>
<form method="POST" action="http://laravel.dv/admin/blog/post/store" id="create-post" enctype="multipart/form-data">
<input type="hidden" name="_token" value="2HeXBBKd1HSmpuGvjYqF1KygbGsCQaZtkuUthi1s">
<div class="page-title">
<h1>Create A Blog</h1>
</div>
<br>
<div class="row">
<div class="col-12">
<div class="form-control">
<input type="text" id="title" name="title" value="" placeholder="Title">
</div>
<div class="form-control">
<input type="text" id="slug" name="slug" value="" placeholder="Slug">
</div>
<div class="form-control">
<input type="file" name="image" placeholder="Image upload">
</div>
<div style="margin: 0 0 20px;">
<textarea name="body" id="summernote"></textarea>
</div>
</div>
<div class="col-12">
<input type="submit" name="btnSubmit" class="btn-primary" value="Save Post" />
</div>
</div>
</form>
<script>
document.forms[0].addEventListener("input", syncData);
function syncData(e) {
const form = e.currentTarget;
const active = e.target;
const fields = form.elements;
let txt;
if (active.type === 'text') {
txt = active.value.toLowerCase().replace(/\s+/g, '-');
console.log(txt);
active.title = txt;
fields.title.value = txt;
fields.slug.value = txt;
}
}
</script>
</body>
</html>
如果xml中记录的其他字段不相等,则仅采用第一条记录的值