Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

XSL: How to specify a relative image path

Posted on 2003-11-11
4
Medium Priority
?
641 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 400 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

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 …
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…

772 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