【发布时间】:2018-07-24 17:57:12
【问题描述】:
给定以下 XML 文档:
<?xml version="1.0" encoding="utf-8"?>
<Store>
<Location>
<State>WA</State>
</Location>
<Transaction>
<Category>Fruit</Category>
</Transaction>
<Customer>
<Category>Rewards</Category>
</Customer>
<Document>
<!-- Huge XML blob here -->
</Document>
</Store>
如何编写 XSLT(版本 1 或 2)将其转换为以下 XML 文档:
<?xml version="1.0" encoding="utf-8"?>
<Transaction>
<Account>
<Type>Rewards</Type>
</Account>
<Type>
<Department>Fruit</Department>
</Type>
<Document>
<!-- Huge XML blob here -->
</Document>
</Transaction>
?
基本上,我需要重新排列/重命名一些元素,删除一些元素,并复制一些元素,就像它们在原始文件中一样。
- Store/Location/State 元素值被删除。
- Store/Transaction/Fruit 元素已移动/重命名为 Transaction/Type/Department。
- Store/Customer/Category 移至 Transaction/Account/Type。
- Store/Document 元素连同其所有未更改的子元素一起复制到作为 Transaction/Document 元素的结果中。
【问题讨论】: