热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

xsl:import或xsl:include的相对路径-Relativepathforxsl:importorxsl:include

IamtryingtouseVBScripttodoanXSLTtransformonanXMLobject.TheXSLfileImtranslatingi

I am trying to use Vbscript to do an XSLT transform on an XML object.
The XSL file I'm translating includes the directive. If I use the absolute URL (http://localhost/mysite/script.xsl), it imports the style sheet fine; however, if I use the relative path (script.xsl) it reports "resource not found." I need to be able to port this amongst a set of machines, so I need to be able to use the relative URI. Any suggestions?

我试图使用Vbscript对XML对象进行XSLT转换。我正在翻译的XSL文件包括 指令。如果我使用绝对URL(http://localhost/mysite/script.xsl),它会很好地导入样式表;但是,如果我使用相对路径(script.xsl),它会报告“找不到资源”。我需要能够在一组机器中移植它,所以我需要能够使用相对URI。有什么建议么?

Notes:

笔记:

  • Vbscript file is at http://localhost/myscript.asp
  • Vbscript文件位于http://localhost/myscript.asp
  • first XSL file is at http://localhost/mysite/styles.xsl
  • 第一个XSL文件位于http://localhost/mysite/styles.xsl
  • second XSL file is at http://localhost/mysite/script.xsl
  • 第二个XSL文件位于http://localhost/mysite/script.xsl
  • using the relative path mysite/script.xsl also does not work
  • 使用相对路径mysite / script.xsl也不起作用

Addendum:

附录:

Thanks, everyone, for your answers. The more I dig into the code that is doing this, the stranger it is. myscript.asp is a rather unusual compilation of code. What happens is styles.xsl is included in the HTML output of myscript.asp as an XML chunk () and then that chunk is loaded as a stylesheet, using Vbscript, on the client side. This stylesheet is then used to transform an XML chunk that is retrieved via XMLHTTP. So the problem is the context of styles.xsl is the HTML on the client side and has no relation to where script.xsl is.

谢谢,大家,谢谢你的回答。我越是深入研究这样做的代码,它就是陌生人。 myscript.asp是一个相当不寻常的代码汇编。 what.xsl作为XML块( )包含在myscript.asp的HTML输出中,然后在客户端使用Vbscript将该块作为样式表加载。然后,此样式表用于转换通过XMLHTTP检索的XML块。所以问题是styles.xsl的上下文是客户端的HTML,与script.xsl的位置无关。

7 个解决方案

#1


1  

The current directory for xsl:import, xsl:include, and the document() function is the directory containing the transform that uses them. So the xsl:import directive that you've said you're using ought to be working.

xsl:import,xsl:include的当前目录和document()函数是包含使用它们的转换的目录。所以你说你正在使用的xsl:import指令应该正常工作。

The only thing I can think of that might affect this: if you use a relative path, the file's being read directly from the file system, while if you use an absolute URI, it's being retrieved from the web server. Is it possible that there's some security setting that's preventing scripts from reading files in this directory?

我唯一能想到的可能会影响到这一点:如果使用相对路径,则直接从文件系统读取文件,而如果使用绝对URI,则从Web服务器检索文件。有可能是某些安全设置阻止脚本读取此目录中的文件吗?

#2


1  

@Jon I think you are very close... but shouldn't it be...

@Jon我觉得你很亲密......但不应该......


...with a leading slash?

......有一个领先的斜线?

#3


1  

I would tackle this by running Sysinternals Process Monitor. With this tool running, you can actually see what files your script tries to open, even if they don't exist.

我会通过运行Sysinternals Process Monitor来解决这个问题。运行此工具后,您可以实际查看脚本尝试打开的文件,即使它们不存在也是如此。

#4


0  

Is it possible that the "current directory" for purposes of the relative path might be the location of your ASP page, not your XSL file? In other words, if you haven't already, you might try:

出于相对路径的目的,“当前目录”是否可能是ASP页面的位置,而不是您的XSL文件?换句话说,如果你还没有,你可以尝试:


#5


0  

I often run into this problem because there is a custom URI resolver being used by a library I can't see (or don't know about because I didn't read pertinent documentation.) I can't remember if this is spec or not but in the Saxon/java world, the custom URI resolver gets first crack at trying to resolve URI's for include/import statements as well as the document() function. If it can't resolve the URI, a default URI resolver gives it a try, which usually never misses when then URI is absolute.

我经常遇到这个问题,因为有一个我无法看到的库使用的自定义URI解析器(或者因为我没有阅读相关文档而不知道。)我不记得这是规范还是不是在Saxon / java世界中,自定义URI解析器在尝试解析包含/导入语句的URI以及document()函数时首先得到了解决方案。如果它无法解析URI,则默认的URI解析器会尝试一次,当URI绝对时,通常永远不会错过。

So, it's probably something in the ASP engine that is using a context driven URI resolver based on the app context.

因此,ASP引擎可能正在使用基于应用程序上下文的上下文驱动的URI解析器。

#6


0  

First Attempt:

第一次尝试:

I tried including script.xsl as another xml chunk and changing the import statement in every way I could imagine but without success.

我尝试将script.xsl包含为另一个xml块,并以我能想象的各种方式更改import语句,但没有成功。

Final solution:

最终解决方案

Since the absolute url for includeing script.xsl worked from the beginning, my final solution was to convert style.xsl to style.asp with the correct doctype. In this file I was then able to retrieve the server name, protocol and path and echo them into the right place in the import statement using asp. Then, when this file got included in mysscript.asp, it had the correct absolute url for the server. This is a bit of a hack but the only way I found to solve this rather convoluted situation.

由于包含script.xsl的绝对URL从一开始就起作用,我的最终解决方案是将style.xsl转换为具有正确doctype的style.asp。在这个文件中,我随后能够检索服务器名称,协议和路径,并使用asp将它们回显到import语句中的正确位置。然后,当此文件包含在mysscript.asp中时,它具有服务器的正确绝对URL。这有点像黑客,但我发现解决这个相当复杂的情况的唯一方法。

#7


-1  

You need a variable that defines the approot, or webroot when loading JS, Image or CSS files.

在加载JS,Image或CSS文件时,您需要一个定义approot或webroot的变量。

 

or if you have the value in the XML,

或者如果您在XML中有值,

 

推荐阅读
author-avatar
沉沉浮浮触涙水
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有