【问题标题】:Chrome does not apply my XSLT stylesheet to my local XML fileChrome 不会将我的 XSLT 样式表应用于我的本地 XML 文件
【发布时间】:2016-03-08 09:13:24
【问题描述】:

我将这两个文件放在同一个本地文件夹中。 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>

【问题讨论】:

  • 我用firefox 对其进行了测试,一切正常。可能是客户端 XSLT 转换的chrome 安全问题。例如,NoScript 也在 firefox 中阻止了这一点。尝试禁用file:///... 的一些安全设置。
  • 这是 Chrome 的安全设置。您不能像这样使用本地 XSL 样式表;样式表必须位于 Web 服务器上,并且与您的 XML 位于同一服务器上。

标签: xml xslt


【解决方案1】:

您可能无法通过 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>

【讨论】:

    猜你喜欢
    • 2022-09-23
    • 2015-03-17
    • 1970-01-01
    • 2013-01-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-06-25
    • 2019-08-05
    相关资源
    最近更新 更多