英文:
Why do browsers disallow fetch of XSLT stylesheet when URL has multiple query string parameters
问题
我有一个XML资源,其中在处理指令中引用了一个XSLT样式表,该处理指令具有一个href
属性。该属性的URL可以有一个查询字符串参数,也可以没有。然而,当URL具有多个查询字符串参数时,浏览器似乎甚至不会获取样式表。为什么会发生这种情况?
这是我的意思。首先,我有XML/XSLT文件,改编自w3schools示例,保存在本地磁盘上,命名为scratch.xml
和style.xml
。我编辑了XML文件,在顶部附近添加了这个处理指令(第二行):
<?xml-stylesheet href="style.xsl" type="text/xsl"?>
我在此目录中运行一个Web服务器,使用以下命令:
python3 -m http.server
如果我在浏览器中获取位于http://localhost:8000/scratch.xml的XML文件,它会获取样式表并正常渲染。如果我更改href
属性并添加一个查询字符串参数,使其看起来像这样:
<?xml-stylesheet href="style.xsl?foo=1" type="text/xsl"?>
它会获取样式表并正常渲染。然而,如果我更改href
属性并添加一个以上的参数,使其看起来像这样:
<?xml-stylesheet href="style.xsl?foo=1&bar=2" type="text/xsl"?>
浏览器甚至停止尝试获取样式表。这在Chrome和Firefox中都发生。我通过嗅探流量来验证它甚至没有请求样式表:
ngrep -d lo port 8000
说实话,我觉得这令人困惑。
我至少尝试过两种不同的浏览器,以及至少两种不同的Web服务器(nginx和Python服务器)。我没有预期样式表URL的形式会有任何影响。
英文:
I have an XML resource that references an XSLT stylesheet in a processing instruction, which has an href
attribute. The URL for that attribute can have one query string parameter or none. However, when the URL has more than one query string parameter the browser seems not even to fetch the stylesheet. Why does this happen?
Here's what I mean. First, I have XML/XSLT files adapted from this w3schools example, saved to local disk as scratch.xml
and style.xml
. I edited the XML file to add this processing instruction near the top (second line):
<?xml-stylesheet href="style.xsl" type="text/xsl"?>
I'm running a web server in this directory using:
python3 -m http.server
If I get the XML file in the browser at http://localhost:8000/scratch.xml it fetches the stylesheet and renders fine. If I change the href
attribute and add one query string parameter so that it looks like this:
<?xml-stylesheet href="style.xsl?foo=1" type="text/xsl"?>
it fetches the stylesheet and renders fine. However, if I change the href
attribute and add one more parameter so that it looks like this:
<?xml-stylesheet href="style.xsl?foo=1&bar=2" type="text/xsl"?>
the browser stops even trying to fetch the stylsheet. This occurs both in Chrome and in Firefox. I verified that it's not even requesting the stylesheet by sniffing the traffic:
ngrep -d lo port 8000
I find this baffling, honestly.
I've tried at least two different browsers, and I've tried at least two different web servers (nginx and the python server). I didn't expect the form of the stylesheet URL to have an bearing at all.
答案1
得分: 4
Your XML is not well-formed because the &
character needs to be escaped as &amp;
.
英文:
Your XML is not well-formed because the &
character needs to be escaped as &amp;
.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论