Solved

XSL: How to specify a relative image path

Posted on 2003-11-11
4
608 Views
Last Modified: 2006-11-17
Hi

Let's assume that my xml stuff is located in the directory C:\xml
In there, I have an XSL file which references to an image located in C:\xml\img using a relative path:

For example:

<xsl:template match="/">

blah blah blah
<img src="img/image.gif">

</xsl:template>

Strangely enough, the relative path seems to be followed, beginning from C: and not from C:\xml, and therefore, the image is not displayed (i.e. the source of the image is C:\img\image.gif and not C:\xml\img\image.gif).

How do I fix this, as absolute URLs are NOT an option?
0
Comment
Question by:IconMan7
  • 2
4 Comments
 
LVL 26

Accepted Solution

by:
rdcpro earned 100 total points
ID: 9726113
Under what context is the XSL processing?  that is, is this a server-side transformation using IIS and perhaps ASP, or is it happening on the client side, running the in the context of the filesystem, or possibly several other contexts?  Is the XML in the same directory?

If you're doing the transform via a stylesheet processing instruction in the XML, remember, the image path is relative to wherever the *browser* thinks is home...which would be the location of the XML, not the XSLT.

In an example page that I have, with the XML and XSL in c:/foo/bar and the images in c:/foo/bar/images, this works:

<img src="{@href}" width="{@width}" height="{@height}"/>

where @href is:   href="images/img2.jpg"

Regards,
Mike Sharp
0
 
LVL 3

Author Comment

by:IconMan7
ID: 9726295
The .xml and the .xsl file are in the same directory.  The images are located in a subdirectory called img.  These files will be downloadable by users later on and will be viewable with internet explorer, so it's going to be client-side.  Also, I would prefer not to work with attributes ({@image}) but with paths which I specify in the XSL file.

In summary:

.xsl and .xml are located in C:\xml
the images are located in C:\xml\img

When I refer to an image in the XLS file with the path src="img/image.gif", it shows no image, only a red x.  When I look at the properties of this red x, it shows the image's path as C:\img\image.gif, which is wrong since it should be C:\xml\img\image.gif.
0
 
LVL 6

Expert Comment

by:PeterCiuffetti
ID: 9732186
By what means are you loading the XML and performing the transform?

Method 1:

...Load the XML via the location bar and the XSL via a processing instruction...

Location bar: C:\xml\somefile.xml

Inside somefile.xml, the stylesheet is loaded via processing instruction..

<?xml-stylesheet type='text/xsl' href='somefile.xsl'?>

Method 2:

Load an HTML file that then uses script to load somefile.xml and transform it with somefile.xsl.

Depending on the method, the browser is going to have a current directory that is either c:\XML or not.  And unless the current directory is C:\XML, the relative path to the image will fail.  Based on your post, it appears that the browser thinks C:\ is the current directory.

0
 
LVL 3

Author Comment

by:IconMan7
ID: 10087144
Looks like that will do the trick.  Thanks!  And my apologies for responding so late.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Browsing the questions asked to the Experts of this forum, you will be amazed to see how many times people are headaching about monster regular expressions (regex) to select that specific part of some HTML or XML file they want to extract. The examp…
Many times as a report developer I've been asked to display normalized data such as three rows with values Jack, Joe, and Bob as a single comma-separated string such as 'Jack, Joe, Bob', and vice versa.  Here's how to do it. 
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question