Chrome无法用xsl显示xml文档

今天在做一个xml的小试验时,发现Chrome竟然无法显示经过xsl修饰的文档!!这么高级的浏览器不应该存在这样的情况啊。经过一翻折腾加google后,发现确实是因为Chrome太高级了所以无法显示:因为安全机制,Chrome不允许本地的xml访问本地的xsl。
解决方案:
1. 换IE或firefox。
2. 把文档上载到web服务器,从服务器可正常访问。
3. 命令行启动chrome的时候加上--allow-file-access-from-files参数。


参考:http://stackoverflow.com/questions/4558160/xsl-not-working-in-google-chrome


测试xml:test.xml

<!--test.xml-->
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="test.xsl"?>
<booklist>
    <book classify="computer science">
        <ISBN>001</ISBN>
        <title>c++ primer</title>
        <authorlist>
            <author>Stanley B. Lippman</author>
            <author>Josee Lajoie</author>
        </authorlist>
    </book>
    <book classify="computer science">
        <ISBN>002</ISBN>
        <title>Advanced Programming in the UNIX Environment</title>
        <authorlist>
            <author>W. Richard Stevens</author>
            <author>Stephen A. Rago</author>
        </authorlist>
    </book>
</booklist>

测试xsl: test.xsl

<!--test.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>
            <head>
                <title>Book Information</title>
            </head>
            <body>
                <center>
                    <h2>BOOK</h2>
                    <table  border="1" cellspacing="0" cellpadding="0" style="width: 60%;text-align: center">
                        <tr>
                            <th>ISBN</th>
                            <th>Classification</th>
                            <th>Book Title</th>
                            <th>Author(s)</th>
                        </tr>
                        <xsl:apply-templates/>
                    </table>
                </center>
            </body>
        </html>
    </xsl:template>
    <xsl:template match="book">
        <tr>
            <td>
                <xsl:value-of select="./ISBN"/>
            </td>
            <td>
                <xsl:value-of select="@classify"/>
            </td>
            <td>
                <xsl:value-of select="./title"/>
            </td>
            <td>
                <xsl:value-of select=".//author[position()=1]"/>
                <xsl:value-of select=".//author[position()>1]"/>
            </td>
        </tr>
    </xsl:template>
</xsl:stylesheet>
  • 6
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值