解析 JavaScript 函数中的同级文件夹

发布于 2024-08-28 02:14:56 字数 939 浏览 2 评论 0原文

我试图将 XML 和 XSLT 的两条路径传递给 JavaScript 函数。在下面的示例 HTML 中,在 xslt() 函数中使用“../xsl/filename”似乎对我不起作用。如果我将路径指定为“./filename”,但这确实有效。

有谁知道我如何解决这个问题或找到某种方法可以在没有绝对路径引用的情况下指定同级文件夹?我不想更改我的文件路径,因为我的开发环境是使用以特定方式构建的 xslt、示例数据和源代码设置的。

提前致谢 贾门

<html>
<head>
<title></title>
<script type="text/javascript" src="../lib/jsunit/app/jsUnitCore.js"></script>
<script type="text/javascript" src="../lib/jquery-1.2.3.js"></script>
<script type="text/javascript" src="../lib/jquery.xslt.js"></script>
</head>
<body>
<div id="bla"></div>
<script type="text/javascript">
$('#bla').xslt("../sampledata/response1.xml", "../xslt/resultFormatter.xsl");

//function testjQuery() {
//  $('#bla').xslt("../sampledata/response1.xml", "../xslt/resultFormatter.xsl");
//}
</script>
</body>
</html>

I am trying to pass into an JavaScript function two paths for an XML and XSLT. It would appear that in the sample HTML below that the use of "../xsl/filename" does not work for me in the xslt() function. If I specify the path as being "./filename" though this does work.

Does anyone know how I can work around this or find some way that I can specify a sibling folder without an absolute path reference? I would prefer not to have to change my file paths as my development environment is set up with the xslt's, sample data and source code structured in a particular way.

Thanks in advance
Jamen

<html>
<head>
<title></title>
<script type="text/javascript" src="../lib/jsunit/app/jsUnitCore.js"></script>
<script type="text/javascript" src="../lib/jquery-1.2.3.js"></script>
<script type="text/javascript" src="../lib/jquery.xslt.js"></script>
</head>
<body>
<div id="bla"></div>
<script type="text/javascript">
$('#bla').xslt("../sampledata/response1.xml", "../xslt/resultFormatter.xsl");

//function testjQuery() {
//  $('#bla').xslt("../sampledata/response1.xml", "../xslt/resultFormatter.xsl");
//}
</script>
</body>
</html>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

神妖 2024-09-04 02:14:56

一个活生生的例子将为我提供最快的方法来深入研究这个问题,但取而代之的是……

恐怕你将不得不进行一些调试。

您可以引用至少一层深度的相对路径,因为拉入 JS 源文件的标头也会这样做,因此可以排除网络服务器的问题。

处理和提取资源似乎发生在客户端,因此打开 Firebug 控制台或其他东西,让您可以了解 JS 环境中发生的情况。

如果你在那里空白,请深入研究源头。

查看

http:// /johannburkard.de/software/xsltjs/apidoc/overview-summary-jquery.xslt.js.html

有两个不同的路径,

if (document.recalc) { // IE 5+
    // EDIT : Path 1 
} else if ( /* EDIT : conditions */) { // Mozilla 0.9.4+, Opera 9+
    // EDIT : Path 2 
} // EDIT : No final else, so a silent failure

第二个让您悲伤的参数

var str = /^\s*</;

在两个路径中都与正则表达式匹配。无论您选择哪条路径,请设置断点并亲自测试这些情况(使用您一直使用的 xslt 参数值)。消除可能性并继续沿着处理链向下移动,直到找到故障点。

我猜想原作者没有预料到相对路径的地方存在正则表达式匹配/字符串处理错误。

A live example would give me the quickest way to drill down on this, but in lieu of that..

You're going to have to do a bit of debugging, I'm afraid.

You can reference relative paths at least one level deep because the headers pulling in the JS source files do that too, so that rules out issues with the webserver.

Processing and pulling in resources seems to happen client-side, so open up a Firebug console or something else that gives you a view of what's happening in your JS environment.

If you draw a blank there, dig into the source.

Take a look at the source code in,

http://johannburkard.de/software/xsltjs/apidoc/overview-summary-jquery.xslt.js.html

There are two different paths,

if (document.recalc) { // IE 5+
    // EDIT : Path 1 
} else if ( /* EDIT : conditions */) { // Mozilla 0.9.4+, Opera 9+
    // EDIT : Path 2 
} // EDIT : No final else, so a silent failure

The second parameter that's giving you grief is matched against the regex,

var str = /^\s*</;

in both paths. Whichever path you're going down, set a breakpoint and test these cases yourself (with both the xslt parameter values you've been using). Eliminate possibilities and keep going down the processing chain until you find your failure point.

I'd guess that there's a regex match/string handling bug somewhere down the line where the original author didn't anticipate relative paths.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文