Solved

XSL: How to specify a relative image path

Posted on 2003-11-11
4
610 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
The Confluence of Individual Knowledge and the Collective Intelligence At this writing (summer 2013) the term API (http://dictionary.reference.com/browse/API?s=t) has made its way into the popular lexicon of the English language.  A few years ago, …
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

710 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