首页 > 解决方案 > XML 在应用 XLST 转换后是空白的?

问题描述

不确定我是否在这里遗漏了什么,因为这是我第一次这样做。如果重要的话,这两个文件都在同一个文件夹中(xml 和 xsl)。

xml 示例:

<?xml-stylesheet type="text/xsl" href="cd_catalog.xsl"?>
<CATALOG>
    <CD>
        <TITLE>Empire Burlesque</TITLE>
        <ARTIST>Bob Dylan</ARTIST>
        <COUNTRY>USA</COUNTRY>
        <COMPANY>Columbia</COMPANY>
        <PRICE>10.90</PRICE>
        <YEAR>1985</YEAR>
    </CD> 
</CATALOG>

还有我的 xsl 文件:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    exclude-result-prefixes="xs"
    version="2.0">
    
    <xsl:template match="/">
        <html>
            <body>
                <h1>Title</h1>
                <table border="1">
                    <tr bgcolor="#9acd32">
                        <th>Title</th>
                        <th>Artist</th>
                        <th>Year</th>
                        <th>Price</th>
                    </tr>
                    <xsl:for-each select="CATALOG/CD">
                        <tr>
                            <td><xsl:value-of select="TITLE"/></td>
                            <td><xsl:value-of select="ARTIST"/></td>
                            <td><xsl:value-of select="YEAR"/></td>
                            <td><xsl:value-of select="PRICE"/></td>
                        </tr>
                    </xsl:for-each>
                </table>
            </body>
        </html>
    </xsl:template>
    
</xsl:stylesheet> 

标签: xmlxslt

解决方案


推荐阅读