Xml XSL模板匹配返回意外数据

Xml XSL模板匹配返回意外数据,xml,xslt,Xml,Xslt,当我应用以下xslt:- <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:template match="//cd[year=2988]"> <html> <body> <h2>My CD Collection</h2> <table border="1">

当我应用以下xslt:-

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="//cd[year=2988]">
  <html>
  <body>
    <h2>My CD Collection</h2>
    <table border="1">
      <tr bgcolor="#9acd32">
        <th>Title</th>
        <th>Artist</th>
      </tr>
      <tr>
        <td><xsl:value-of select="title"/></td>
        <td><xsl:value-of select="artist"/></td>
      </tr>
    </table>
  </body>
  </html>
</xsl:template>
</xsl:stylesheet>
是在html标记结束后出现的。应用了模板并形成了表,但为什么数据会再次出现在结果中 我是xslt新手。请告诉我我想
会制造麻烦。。。这就是所谓的标准。尝试移除它

编辑:用于输入xml

<?xml version="1.0" encoding="UTF-8"?>
<catalog>
    <cd>
        <title>Empire Burlesque</title>
        <artist>Bob Dylan</artist>
        <country>USA</country>
        <company>Columbia</company>
        <price>10.90</price>
        <year>2988</year>
    </cd>
    <cd>
        <title>Greatest Hits</title>
        <artist>Dolly Parton</artist>
        <country>USA</country>
        <company>RCA</company>
        <price>9.90</price>
        <year>1982</year>
    </cd>
</catalog>

皇帝讽刺剧
鲍勃·迪伦
美国
哥伦比亚
10.90
2988
最成功的
多莉·帕顿
美国
RCA
9.90
1982
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="/">
        <xsl:apply-templates select="//cd[year=2988]" />
    </xsl:template>

    <xsl:template match="cd">
        <html>
            <body>
                <h2>My CD Collection</h2>
                <table border="1">
                    <tr bgcolor="#9acd32">
                        <th>Title</th>
                        <th>Artist</th>
                    </tr>
                    <tr>
                        <td>
                            <xsl:value-of select="title"/>
                        </td>
                        <td>
                            <xsl:value-of select="artist"/>
                        </td>
                    </tr>
                </table>
            </body>
        </html>
    </xsl:template>
</xsl:stylesheet>

我的CD收藏
标题
艺术家
结果

<html>
    <body>
        <h2>My CD Collection</h2>
        <table border="1">
            <tr bgcolor="#9acd32">
                <th>Title</th>
                <th>Artist</th>
            </tr>
            <tr>
                <td>Empire Burlesque</td>
                <td>Bob Dylan</td>
            </tr>
        </table>
    </body>
</html>

我的CD收藏
标题
艺术家
皇帝讽刺剧
鲍勃·迪伦

即使在将其移除后。。我得到了同样的结果。你能告诉我你是如何测试它的吗?我用的是Altova。我在你们提供的链接上试用了这个应用程序(顺便说一句,很好的工具,我不知道)而且它也工作正常。非常感谢您的回复…您能尝试一下这个输入重复一下它给出了上面的问题吗------------------------------------帝国滑稽剧鲍勃·迪伦美国哥伦比亚10.90 2988最受欢迎的多莉·帕顿美国RCA 9.90 1982啊,我知道了。我改进了我的答案。
<?xml version="1.0" encoding="UTF-8"?>
<catalog>
    <cd>
        <title>Empire Burlesque</title>
        <artist>Bob Dylan</artist>
        <country>USA</country>
        <company>Columbia</company>
        <price>10.90</price>
        <year>2988</year>
    </cd>
    <cd>
        <title>Greatest Hits</title>
        <artist>Dolly Parton</artist>
        <country>USA</country>
        <company>RCA</company>
        <price>9.90</price>
        <year>1982</year>
    </cd>
</catalog>
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:template match="/">
        <xsl:apply-templates select="//cd[year=2988]" />
    </xsl:template>

    <xsl:template match="cd">
        <html>
            <body>
                <h2>My CD Collection</h2>
                <table border="1">
                    <tr bgcolor="#9acd32">
                        <th>Title</th>
                        <th>Artist</th>
                    </tr>
                    <tr>
                        <td>
                            <xsl:value-of select="title"/>
                        </td>
                        <td>
                            <xsl:value-of select="artist"/>
                        </td>
                    </tr>
                </table>
            </body>
        </html>
    </xsl:template>
</xsl:stylesheet>
<html>
    <body>
        <h2>My CD Collection</h2>
        <table border="1">
            <tr bgcolor="#9acd32">
                <th>Title</th>
                <th>Artist</th>
            </tr>
            <tr>
                <td>Empire Burlesque</td>
                <td>Bob Dylan</td>
            </tr>
        </table>
    </body>
</html>