另一台计算机/服务器上文件的 document() 函数 [英] document() function for a file on another computer/server

查看:27
本文介绍了另一台计算机/服务器上文件的 document() 函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我理解document()的用法如下.

I understand the use of document() as follows.

<xsl:value-of select="document('path\to\docuemnt.xml')/RootElement/Element"/>

而且这必须是父 XSL 文件的相对路径.但是,如果我需要引用托管在本地网络另一台服务器上的文件怎么办?我试过这样的事情.

And this has to be a relative path to the parent XSL file. But what if I need to reference a file which is hosted on another server on the local network? I've tried such things as.

<xsl:value-of select="document('\\servername\path\to\document.xml')/RootElement/Element"/>

但是这会引发错误,因为它看起来在

But this throws an error, because it looks in

C:\path\to\xsl\\servername\path\to\document.xml

当然不存在.

推荐答案

此解决方案仅与 Saxon-HE 9.4.0.3N XSLT 处理器有关,在控制台应用程序形式中,在 Windows 7 上.

This solution only relates to the Saxon-HE 9.4.0.3N XSLT processor, in the console application form, on Windows 7.

在我的实验中,我发现 document() 函数将接受文件名或 URI.但是我会避免使用文件名,因为它们需要是简短的.如果使用长格式,文件名将被拒绝.

In my experimentation, I found that the document() function will accept file names or URIs. However I would avoid filenames because they need to be short-form. If you use long-form, the file-name will be rejected.

假设您的文档是...

c:\path\to\document.xml

在映射到驱动器j"的服务器servername"上.

on server 'servername' which is mapped to drive 'j'.

要从此使用形成 URI 作为 document() 参数值...

To form a URI from this use as the document() parameter value...

file:///j:/path/to/document.xml

关于 URI,我误认为撒克逊人不接受长格式.这仅适用于文件名.然而,有许多问题......

In relation to the URI, I was mistaken about Saxon not accepting long-form. This only applies to filenames. However, there are a number of gotchas...

  1. 注意正斜杠.反斜杠不起作用.
  2. 我还没有找到一种方法来构建一个可行的文件:只有 UNC 名称的 URI.您需要将驱动器映射到一个字母.
  3. 由于任何原因无法打开文档将被报告为相同的错误.对于文件系统,有很多事情可能会出错,如果您无法打开文件,则认为 URI 错误是不安全的.无法在特定时间打开文件的原因可能有很多.
  4. 注意防火墙问题.这些都发挥了作用.
  5. 许多文本编辑器(例如 NotePad++)假定,在没有 BOM 且未使用两种 UTF-16 编码之一进行编码的情况下,文本文件会在系统代码页中进行编码.Saxon 将默认假设该文件以 UTF-8 编码,因此如果您在 NotePad++ (ä) 中使用我的代码页有一个看起来像这样的字符,Saxon 会吐出这个假人,并报告它无法打开文件.(旁白:我不确定我的代码页是什么.我的操作系统是 Win7,当前系统区域设置是英语(澳大利亚).系统本地设置决定了系统代码页).Saxon 不会打开文档的原因是,在某些代码页中编码的 (ä) 会导致字节序列不是有效的 UTF-8 序列.
  6. 底层操作系统不支持非 URL 路径的 URI 路径.Saxon 可能会如实说它支持与 document() 函数相关的 URI,但这并没有解决任何问题,因为在实践中,您不能使用它们.- 至少不是在 o/s 的 windows 系列上.
  7. 请忽略 MSDN 页面 关于文件协议.Saxon document() 函数不接受该页面上建议的 URL 形式(带有 | 字符等).使用我上面建议的表格.我已经对其进行了测试并且可以正常工作.
  1. Note the forward slashes. Backslashes will not work.
  2. I have not found a way to build a workable file: URI with just UNC names. You need to make a drive mapping to a letter.
  3. Any failure to open the document for any reason will be reported as the same error. With file system, there are so many things that can go wrong, that if you can't open the file, it is not safe to assume that the URI is wrong. There could be many mundane reasons why a file cannot be opened at a particular time.
  4. Beware of firewall issues. These play a role.
  5. Many text editors, such as NotePad++ assume, in the absence of a BOM and not encoded in one of the two UTF-16 encodings, that a text file is encoded in the system code-page. Saxon will make the default assumption that the file is encoded in UTF-8 so if you have a character that looks like this in NotePad++ (ä) with my code-page, Saxon will spit the dummy, and report that it is unable to open the file. (Aside: I'm not sure what my code-page is. My o/s is Win7 and the Current system locale is English (Australia). It is the system local that determines the system code-page). The reason why Saxon will not open the document is that the (ä) encoded in some code-page results in a sequence of bytes which is not a valid UTF-8 sequence.
  6. URI paths which are not URL paths are not supported by the underlying operating system. Saxon may well truthfully say that it supports URIs in relation to the document() function, but that doesn't boil any cabbages, because in practice, you can't use them. - Well at least not on the windows family of o/s.
  7. Please ignore the MSDN page on the file protocol. The form of URL suggested on that page (with the | character etc) is not accepted by the Saxon document() function. Use the form that I have suggested above. I have tested it and it works.

这篇关于另一台计算机/服务器上文件的 document() 函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆