Chrome不会将我的XSLT样式表应用于我的本地XML文件

时间:2016-03-08 09:13:25

标签: xml xslt

我将这两个文件放在同一个本地文件夹中。 XML文件是1.xml,xsl文件是1.xsl。当我在Chrome中打开xml时,它显示为空,对于xsl文件,它会显示此消息“此XML文件似乎没有与之关联的任何样式信息。文档树如下所示。”和xml树。

这是我的xml

     <?xml version="1.0"?>
        <?xml-stylesheet type="text/xsl" href="1.xsl"?>

        <myBcollection>
        <businesscard>
        <organisation>V of S</organisation>
        <address>
            <no>42</no>
            <street>Foster Street</street>
            <city>Sydney</city>
            <county>sss</county>
        </address>
        <contactdetails>
            <contactNo type="landline">+94 71232312</contactNo>
            <fax>313234</fax>
            <email>er@gmail</email>
        </contactdetails>
        <website uri="http://w3.org"/>
    </businesscard>

    <businesscard>
        <organisation>Org 2</organisation>
        <address>
            <no>42</no>
            <street>Foster Street</street>
            <city>Sydney</city>
            <county>sss</county>
        </address>
        <contactdetails>
            <contactNo type="landline">1232312</contactNo>
            <fax>313234</fax>
            <email>er@gmail</email>
        </contactdetails>
        <website uri="http://w3.org"/>
    </businesscard>

    <businesscard>
        <organisation>Org 3</organisation>
        <address>
            <no>42</no>
            <street>Foster Street</street>
            <city>Sydney</city>
            <county>sss</county>
        </address>
        <contactdetails>
            <contactNo type="landline">+94 71232312</contactNo>
            <fax>313234</fax>
            <email>er@gmail</email>
        </contactdetails>
        <website uri="http://w3.org"/>
    </businesscard>
</myBcollection>

这是我的xsl

    <?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>

    <table border="1">
        <tr>
        <th>Org nm</th>
        <th>Adress Street</th>
        <th>City</th>
        <th>County</th>
        <th>Fax</th>
        </tr>

        <xsl:for-each select="/">

        <tr>

        <td><xsl:value-of select="myBcollection/businesscard/organisation"/></td>
        <td><xsl:value-of select="myBcollection/businesscard/address/street"/></td>
        <td><xsl:value-of select="myBcollection/businesscard/address/city"/></td>
        <td><xsl:value-of select="myBcollection/businesscard/address/county"/></td>
        <td><xsl:value-of select="myBcollection/businesscard/contactdetails/fax"/></td>
        </tr>
        </xsl:for-each>
    </table>

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

1 个答案:

答案 0 :(得分:0)

您可能无法在本地使用带有chrome的XSL表,但是您可以使用html样式元素来设置xml的样式,您只需确保使用html命名空间。下面是一些样式的xml示例。

<?xml version="1.0" encoding="UTF-8"?>
<note>
    <style xmlns="http://www.w3.org/1999/xhtml">
        to, from, heading, body {display: block; }
    </style>
    <to>Tove</to>
    <from>Jani</from>
    <heading>Reminder</heading>
    <body>Don't forget me this weekend!</body>
</note>