【发布时间】:2016-08-15 19:09:42
【问题描述】:
我有两个需要加入的.xml 文件
第一个文件是Song.xml,如下:
<Songs>
<Song>
<SongID>1</SongID>
<SongName>We dont talk anymore</SongName>
<Author>M-TP</Author>
<UploadBy>admin</UploadBy>
<GerneCode>1</GerneCode>
</Song>
</Songs>
以及从模式生成的 Gerne.xml
<ns2:gernes xmlns="http://www.w3.org/2001/XMLSchema/playlist" xmlns:ns2="https://xml.netbeans.org/schema/genses">
<ns2:gerne>
<GerneCode>1</GerneCode>
<GerneName>Pop</GerneName>
<Image>img-pop.jpg</Image>
</ns2:gerne>
</ns2:gerne>
我想将这些.xml 文件加入到XSL 中,这将为与Gerne.xml 中的GerneName 匹配的每首歌曲添加GerneName。
我试图得到的结果应该是这样的:
<Songs>
<Song>
<SongID>1</SongID>
<SongName>We dont talk anymore</SongName>
<Author>M-TP</Author>
<UploadBy>admin</UploadBy>
<GerneName>Pop</GerneName>
<GerneCode>1</GerneCode>
</Song>
</Songs>
谁能帮我解决这个问题?任何例如或关键字我应该查找这个问题?
【问题讨论】:
-
开始,使用document函数读取
Gerne.xml,得到GerneCode,GerneName,看看GerneCode是否匹配Songs.xml中当前元素的GerneCode和在Songs.xml中的当前元素下复制GerneCode、GerneName。您可以使用 XpathFactory 用于 xpath 表达式和 TransformerFactory ,请参阅:docs.oracle.com/javase/7/docs/api/javax/xml/transform/…) 用于在拥有 xsl 后转换您的 xml。 -
你可以使用 XSLT 2.0 吗?