首页 > 解决方案 > 如何组合多个xml并为组合的XML准备XSLT 以上是一个XML的XSLT

问题描述

如何组合多个 XML 并为组合的 XML 准备 XSLT?我尝试将多个 XML 合并为一个,并尝试为该 XML 准备 XSLT 转换。以上是一个 XML 的 XSLT。需要为组合的 XML 准备 XSLT。

XML-1
<?xml version="1.0" encoding="UTF-8"?>
<catalog>
  <cd>
    <title>Empire Burlesque</title>
    <artist>Bob Dylan</artist>
  </cd>
</catalog>
XML-2
<?xml version="1.0" encoding="UTF-8"?>
<catalog>
  <cd>
    <title>Empire Burlesque-1</title>
    <artist>Bob Dylan-1</artist>
  </cd>
</catalog>

XSLT

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html> 
<body>
  <h2>My CD Collection</h2>
  <table border="1">
    <tr bgcolor="#9acd32">
      <th style="text-align:left">Details</th>
      <th style="text-align:left">XML-1</th>
    </tr>
 <tr>
    <xsl:for-each select="catalog/cd">
         ​  <td>Title</td>
     ​      <td><xsl:value-of select="title"/></td>
    </xsl:for-each>
</tr>

​&lt;tr>
   ​ <xsl:for-each select="catalog/cd">
            <td>Artist</td>
            <td><xsl:value-of select="artist"/></td>
    </xsl:for-each>
</tr>  

</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>

The above is the XSLT for one XML. Need to prepare XSLT for the combined XML

  [1]: https://i.stack.imgur.com/g8ce7.jpg

标签: htmlxmlxslt

解决方案


更改<xsl:for-each select="catalog/cd">为 eg <xsl:for-each select="catalog/cd | document('XML-2.xml')/catalog/cd">,以同时处理第二个文档。


推荐阅读