问题
First a short task description:
There is an XML file which references a xsl stylesheet which is within a *.dll. The beginning of this XML looks as follows:
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type='text/xsl' href='res://name_xsl.dll/frameset.xsl'?>
This xml file can be opened and displayed as an HTML within Internet Explorer and only IE. (The xsl transform the xml to html)
As you can see it references the win32 system folder, in which the dll file is saved. Referencing with "res://" does work.
But now I do not want to store my dll within the system folder, but under a different folder lets say %ALLUSERSPROFILE% (environment variable) which e.g. on Windows XP is C:\Documents and Settings\All Users or on Win7 C:\Users\Public (Not sure about that one).
How do I reference to the dll lying in that folder? Is it possible to do this using environment variables, such that it is system independent? What solution would you recommend. (All html, xsl data is saved locally within the dll on the local computer.)
So far I have tried to change the reference line to the following:
<?xml-stylesheet type='text/xsl' href='file:///c:/Documents and Settings/All Users/name_xsl.dll/frameset.xsl'?>
I have also tried the same with the root folder c: and even without absolute path having all files (xml and dll) in the same folder. All attempts without res:// resulted in the following error message:
The system cannot locate the resource specified. Error processing resource 'file:///C:/Documents and Settings/All Users/name_xsl.dll/... or 'file:///C:/name_xsl.dll/frameset.xsl'
Could you help me out? Why it does not find the file? (filenames are fictive)
回答1:
This is the solution:
<?xml-stylesheet type='text/xsl' href='res://C:%5CDocuments and Settings%5CAll Users%5Cname_xsl.dll/frameset.xsl'?>
Notes:
- You MUST use the res:// protocol to access a resource within a file.
- File system backslashes can be encoded as %5C . Possibly forward slashes will work as well.
Example: I tested this example for the file:// protocol, but it should work the same way as the res: protocol. On my system, I have a text file located at:
C:\Program Files\CodeGear\Delphi for PHP\2.0\privacy.txt
I can access this file, by putting into the nav bar of the Windows File Explorer:
file:///%ProgramFiles%/CodeGear/Delphi for PHP/2.0/privacy.txt
Notice backslashes converted to forward slashes, and no need to escape spaces. This has been tested and it works. The equivalent on the res protocol had not been tested, but it should work the same way, except of course that the res protocol is slightly different in that it also includes a resource index number.
Refer http://msdn.microsoft.com/en-us/library/ie/aa767740(v=vs.85).aspx for syntax.
来源:https://stackoverflow.com/questions/9375283/local-xsl-reference-within-xml-file