Solved

XSL: How to specify a relative image path

Posted on 2003-11-11
4
600 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Looks like that will do the trick.  Thanks!  And my apologies for responding so late.
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Suggested Solutions

The Problem How to write an Xquery that works like a SQL outer join, providing placeholders for absent data on the outer side?  I give a bit more background at the end. The situation expressed as relational data Let’s work through this.  I’ve …
The Client Need Led Us to RSS I recently had an investment company ask me how they might notify their constituents about their newsworthy publications.  Probably you would think "Facebook" or "Twitter" but this is an interesting client.  Their cons…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

728 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now