3

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)

Vladimir S.
  • 450
  • 2
  • 10
  • 23
  • If you can't get the xml rendering correctly. Try this https://stackoverflow.com/questions/49687472/how-to-use-a-relative-path-in-xml-for-xsl-stylesheet/69150280#69150280 – Alvin Smith Sep 12 '21 at 22:32

1 Answers1

1

This is the solution:

<?xml-stylesheet type='text/xsl' href='res://C:%5CDocuments and Settings%5CAll Users%5Cname_xsl.dll/frameset.xsl'?>

Notes:

  1. You MUST use the res:// protocol to access a resource within a file.
  2. 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.

Sean B. Durkin
  • 12,659
  • 1
  • 36
  • 65
  • Also the SPACE needs to be encoded as %20 to work. Forward slashes do not work I believe. – Vladimir S. Feb 22 '12 at 09:50
  • Yes it works now, which is good. Thank you a lot! Is it possible to specify something behind the res: tag which reads in e.g. the folder %ALLUSERSPROFILE% from the environment variables. This I need, since the files referenced are always in the folder under the environment variable and this changes between systems. Are there possibilites within XML or within JavaScript or Visual Basic Script. I tried to find, but was not successful. – Vladimir S. Feb 22 '12 at 14:13
  • @Byron-LimTimothySteffan: Your comment is wrong. In general spaces do not need to be escaped. They only need to be escaped http (referred to as URL encoding). For local XSLT this is not the case. Also Forward slashes do work. It would be absurd if they didnt. The forward slashes are a fundamental part of the protocol lexicon. – Sean B. Durkin Feb 23 '12 at 05:40
  • It is not possible to map special folders within the res: protocol or from plain-vanilla XSLT. However, it might be possible via vendor-specific browser or XSLT extensions or via the application. To answer this, more information about the context is required. Is this code embedded in a html page? Is the page rendered by PHP or pure HTML? Or is the transform on the server side? – Sean B. Durkin Feb 23 '12 at 05:44
  • Well, after some more research, I think it can be done within the res: protocol. Now adjusting answer accordingly. – Sean B. Durkin Feb 23 '12 at 06:13
  • So the context ist as follows: I have a test report which a program outputs as an xml. This xml is transferred via normal xsl (what is plain-vanilla) to a html. Therefore the XML references an xsl which furthermore references other xsl stylesheets, etc. So far we saved dependencies in the system folder res://, but since for win7 adminrights changed, we cant do this there anymore. Also the test report should be viewed on every system and since we cannot use the system folder anymore e.g. %ALLUSERSPROFILE% would be an option to put dependencies. But there seems no way to put it into the xml. – Vladimir S. Feb 23 '12 at 07:54
  • I have checked your solution. It does work on the File Explorer, since this one can resolve environment variables. But out of an XML it cannot be resolved. Some other way? – Vladimir S. Feb 23 '12 at 09:02