Solved

XSL: How to specify a relative image path

Posted on 2003-11-11
4
618 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

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…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

627 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