通过 xslt 转换将 XML 文件转换为 output.xml
arts.xml 文件:
<artworks>
<artwork>
<title>Adoration of the Magi</title>
<author>GHIRLANDAIO, Domenico</author>
<date>1487</date>
<technique>Tempera on wood, diameter: 171 cm</technique>
<location>Galleria degli Uffizi, Florence</location>
<form>painting</form>
<type>religious</type>
</artwork>
</artworks>
author.xml 文件:
<authors>
<author>
<name>AMADEO, Giovanni Antonio</name>
<born-died>b. ca. 1447, Pavia, d. 1522, Milano</born-died>
<nationality>Italian</nationality>
<biography>Giovanni Antonio Amadeo was an Italian early Renaissance sculptor</biography>
</author>
<authors>
output.xml 文件:
<authors>
<author>
<name>AMADEO, Giovanni Antonio</name>
<born-died>b. ca. 1447, Pavia, d. 1522, Milano</born-died>
<nationality>Italian</nationality>
<biography>Giovanni Antonio Amadeo was an Italian early Renaissance sculptor</biography>
<artworks form="architecture">
<artwork date="1473">
<title>Faهade of the church</title>
<technique>Marble</technique>
<location>Certosa, Pavia</location>
</artwork>
</artworks>
</author>
</authors>
artworks.xml 艺术品作者是外键,引用authors.xml 作者 条目。
我想合并这两个 XML 文档并创建一个新的 XML 文件,其中 应存储每位作者的以下信息:姓名、出生日期、国籍、 传记和所有艺术品。艺术品按形式分组,然后按日期排序。为了 每件艺术品、标题、技术和位置的存储
都具有挑战性:)
artworks.xml file:
<artworks>
<artwork>
<title>Adoration of the Magi</title>
<author>GHIRLANDAIO, Domenico</author>
<date>1487</date>
<technique>Tempera on wood, diameter: 171 cm</technique>
<location>Galleria degli Uffizi, Florence</location>
<form>painting</form>
<type>religious</type>
</artwork>
</artworks>
author.xml file :
<authors>
<author>
<name>AMADEO, Giovanni Antonio</name>
<born-died>b. ca. 1447, Pavia, d. 1522, Milano</born-died>
<nationality>Italian</nationality>
<biography>Giovanni Antonio Amadeo was an Italian early Renaissance sculptor</biography>
</author>
<authors>
output.xml file :
<authors>
<author>
<name>AMADEO, Giovanni Antonio</name>
<born-died>b. ca. 1447, Pavia, d. 1522, Milano</born-died>
<nationality>Italian</nationality>
<biography>Giovanni Antonio Amadeo was an Italian early Renaissance sculptor</biography>
<artworks form="architecture">
<artwork date="1473">
<title>Faهade of the church</title>
<technique>Marble</technique>
<location>Certosa, Pavia</location>
</artwork>
</artworks>
</author>
</authors>
The artworks.xml artwork author is a foreign key, referencing the authors.xml author
entries.
I would like to merge these two XML documents and create a new XML file, in which the
following information should be stored for each author: name, born-died, nationality,
biography, and all artworks. The artworks are grouped by form and then sorted on date. For
each artwork, title, technique, and location are stored
it is challanging : )
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
完整的解决方案:
输入:
和:
输出:
编辑:更新以驱动作者处理,这样即使没有任何艺术品的作者也会被包括在内。
A complete solution:
Input:
And:
Output:
Edit: Updated to drive processing by author, so that even authors without any artworks will be included.
这可以解决问题。它演示了许多有用的 XSLT 技术 - 扩展身份转换、Muenchian 分组、使用
document()
合并辅助文档中的数据、抑制空元素的输出 - 这使得它值得全面研究:This does the trick. It demonstrates a number of useful XSLT techniques - extending the identity transform, Muenchian grouping, using
document()
to merge data from a secondary document, suppressing output of empty elements - which made it worth working out in full:我使用 document() 功能:
我使用了 Intel 的 XSLT 命令行工具来进行转换。这是命令行:
I got as far as the merging part of your problem using the document() function:
I used Intel's XSLT command line tool to do the transform. Here's the command line: