我有一个包含Employees Name的 XML文件和由他们完成的Job. XML文件的结构是 – EmployeeAAA@A#B#C#D/EmployeeEmployeeBBB@A#B#C#D/EmployeeEmployeeCCC@A#B#C#D/EmployeeEmployeeDDD@A#B#C#D/Employee 有成千上万的记录,我必须
XML文件的结构是 –
<Employee>AAA@A#B#C#D</Employee> <Employee>BBB@A#B#C#D</Employee> <Employee>CCC@A#B#C#D</Employee> <Employee>DDD@A#B#C#D</Employee>
有成千上万的记录,我必须改变结构 –
<Employee> <Name>AAA</Name> <Jobs> <Job>A</Job> <Job>B</Job> <Job>C</Job> <Job>D</Job> </Jobs> </Employee>
如何在BaseX中使用XQuery完成此操作?
3个XQuery函数,substring-before,substring-after和tokenize用于获取所需的输出.
substring-before用于获取Name.
类似地,substring-after用于获取Job部分.
然后,tokenize函数用于拆分作业.
let $data := <E> <Employee>AAA@A#B#C#D</Employee> <Employee>BBB@A#B#C#D</Employee> <Employee>CCC@A#B#C#D</Employee> <Employee>DDD@A#B#C#D</Employee> </E> for $x in $data/Employee return <Employee> {<Name>{substring-before($x,"@")}</Name>} {<Jobs>{ for $tag in tokenize(substring-after($x,"@"),'#') return <Job>{$tag}</Job> }</Jobs> }</Employee>
HTH …