473,782 Members | 2,393 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

reference to external CSS or JS from XSL stylesheet

How can I make a reference to an external CSS or JS file that is
relative to the XSL stylesheet, and not relative to the XML data?

If you simply put : <link rel="stylesheet " type="text/css"
href="ui/demo.css" ></link>
in your XSL file, this link will always be relative to the location
where the XML file is.
For example, suppose I have following XML data (test.xml):

<?xml version="1.0" ?>
<?xml:styleshee t type="text/xsl" href="ui/show.xsl" ?>
<demo>text</demo>

In a sub-folder "ui" I stored a CSS file (demo.css):
..demo {
color:red;
}

and the following XSL file (show.xsl):

<?xml version="1.0"?>
<xsl:styleshe et xmlns:xsl="http ://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:template match="demo">
<html>
<head>
<title></title>
<link rel="stylesheet " type="text/css" href="ui/demo.css" ></link>
</head>
<body>
<span class="demo"><x sl:value-of select="."/></span>
</body>
</html>
</xsl:template >
</xsl:stylesheet>
As you can see in show.xsl I had to use the relative path
"ui/demo.css" to include the CSS stylesheet, which is logic in the XSL
transformation sense, and it works, but is not a good solution,
because what if I move the XML file to another folder and change the
XSL reference in it? Then the reference to the CSS file will still be
relative to the XML data, and then it does not work anymore.

So, I am looking for a way to include these files relative to the XSL
file. I think there is no way to discover the "uri" to the XSL file,
from within the XSL file, is there? If so, this could be used to
adjust the references.

The only solution that I encountered so far is to store the CSS and JS
data in separate XSL files, and use the xsl:import or xsl:link, and
then use call-template to include the data. For testing and
maintenance I personally do not like this solution either...

Please help...
Jul 20 '05 #1
3 12822
"allard poldermans" <al****@turpinv ision.nl> wrote in message
news:5d******** *************** ***@posting.goo gle.com...
How can I make a reference to an external CSS or JS file that is
relative to the XSL stylesheet, and not relative to the XML data?


When I started putting XML files in a subdirectory, I made soft
links to the library directories in it. So from every directory
with XML files in it, CSS and XSLT (or JS) directories at least
appear as immediate subdirectories, although in reality there's
only one real CSS directory, under the root; all the other ones
are links.

This sort of solves your general problem by assuring that any
other library directory is at ../X.

Groetjes,
Maarten Wiltink
Jul 20 '05 #2
Thanks for your answer, but I'm afraid I don't understand it...

What do you mean with a soft link, do you have an example? Did you
place these links inside the XML files? (I hope not). And what do you
do under the root? In an offline scenario the root would be the root
of the client's pc. I think an example would help.

groetjes, Allard
"Maarten Wiltink" <ma*****@kitten sandcats.net> wrote in message news:<3f******* *************** *@news.xs4all.n l>...
"allard poldermans" <al****@turpinv ision.nl> wrote in message
news:5d******** *************** ***@posting.goo gle.com...
How can I make a reference to an external CSS or JS file that is
relative to the XSL stylesheet, and not relative to the XML data?


When I started putting XML files in a subdirectory, I made soft
links to the library directories in it. So from every directory
with XML files in it, CSS and XSLT (or JS) directories at least
appear as immediate subdirectories, although in reality there's
only one real CSS directory, under the root; all the other ones
are links.

This sort of solves your general problem by assuring that any
other library directory is at ../X.

Groetjes,
Maarten Wiltink

Jul 20 '05 #3
"allard poldermans" <al****@turpinv ision.nl> wrote in message
news:5d******** *************** ***@posting.goo gle.com...
Thanks for your answer, but I'm afraid I don't understand it...

What do you mean with a soft link, do you have an example? Did you
place these links inside the XML files? (I hope not). And what do you
do under the root? In an offline scenario the root would be the root
of the client's pc. I think an example would help.


Excerpted from a recursive directory listing of the local mirror of
my public website:

<logical root>:
total 613
drwxrwxr-x 8 maarten 1024 Nov 4 23:43 ./
drwxrwxr-x 3 maarten 1024 Aug 5 15:07 ../
drwxrwxr-x 2 maarten 1024 Nov 3 14:35 css/
drwxrwxr-x 2 maarten 1024 Nov 2 14:33 dtd/
drwxrwxr-x 2 maarten 1024 Nov 5 17:00 xslt/
drwxrwxr-x 2 maarten 2048 Nov 5 00:19 properties/
-rw-rw-r-- 1 maarten 1584 Nov 4 22:40 caesar.xhtml
-rw-rw-r-- 1 maarten 275 Nov 2 15:58 codefragments.x ml
-rw-rw-r-- 1 maarten 791 Nov 3 19:57 index.html
-rw-rw-r-- 1 maarten 3299 May 3 2002 nohtml.html
-rw-rw-r-- 1 maarten 925 Nov 3 19:58 personal.html
-rw-rw-r-- 1 maarten 2225 Nov 3 19:59 programming.htm l
-rw-rw-r-- 1 maarten 41522 Nov 3 19:59 programmingstyl e.html
-rw-rw-r-- 1 maarten 65670 Nov 3 20:00 properties.html

css, dtd, and xslt are directories with library files; properties contains
content materials.
css:
total 5
drwxrwxr-x 2 maarten 1024 Nov 3 14:35 ./
drwxrwxr-x 8 maarten 1024 Nov 4 23:43 ../
-rw-rw-r-- 1 maarten 206 Nov 3 18:41 delphi-code.css
-rw-rw-r-- 1 maarten 140 Nov 3 18:40 narrative.css
-rw-rw-r-- 1 maarten 174 Nov 3 18:41 programming.css

dtd:
total 4
drwxrwxr-x 2 maarten 1024 Nov 2 14:33 ./
drwxrwxr-x 8 maarten 1024 Nov 4 23:43 ../
-rw-rw-r-- 1 maarten 168 Nov 2 14:33 pages-1.0.dtd
-rw-rw-r-- 1 maarten 264 Nov 1 16:04 pages-1.1.dtd
lrwxrwxrwx 1 maarten 13 Nov 2 14:32 pages-1.dtd -> pages-1.1.dtd
lrwxrwxrwx 1 maarten 11 Oct 23 23:07 pages.dtd -> pages-1.dtd

xslt:
total 22
drwxrwxr-x 2 maarten 1024 Nov 5 17:00 ./
drwxrwxr-x 8 maarten 1024 Nov 4 23:43 ../
-rw-rw-r-- 1 maarten 4624 Nov 2 15:56 codefragments.x slt
-rw-rw-r-- 1 maarten 447 Nov 5 16:57 id.xslt
-rw-rw-r-- 1 maarten 8487 Nov 4 23:43 links.xslt
-rw-rw-r-- 1 maarten 3709 Nov 5 00:02 pages.xslt

properties:
total 82
drwxrwxr-x 2 maarten 2048 Nov 5 00:19 ./
drwxrwxr-x 8 maarten 1024 Nov 4 23:43 ../
lrwxrwxrwx 1 maarten 6 Nov 1 20:28 css -> ../css/
lrwxrwxrwx 1 maarten 6 Nov 2 22:25 dtd -> ../dtd/
lrwxrwxrwx 1 maarten 7 Nov 2 16:47 xslt -> ../xslt/
-rw-rw-r-- 1 maarten 1993 Nov 4 12:45 index.xhtml
-rw-rw-r-- 1 maarten 2022 Nov 4 12:45 index.xml
-rw-rw-r-- 1 maarten 1262 Nov 5 00:12 properties-01.xhtml
-rw-rw-r-- 1 maarten 4244 Nov 4 20:10 properties-02.xhtml
-rw-rw-r-- 1 maarten 4369 Nov 4 20:10 properties-03.xhtml
-rw-rw-r-- 1 maarten 2879 Nov 4 20:10 properties-04.xhtml
-rw-rw-r-- 1 maarten 5258 Nov 4 20:10 properties-05.xhtml
-rw-rw-r-- 1 maarten 6939 Nov 4 20:11 properties-06.xhtml
-rw-rw-r-- 1 maarten 8177 Nov 4 20:12 properties-07.xhtml
-rw-rw-r-- 1 maarten 5203 Nov 4 20:12 properties-08.xhtml
-rw-rw-r-- 1 maarten 7839 Nov 4 20:11 properties-09.xhtml
-rw-rw-r-- 1 maarten 6503 Nov 4 20:11 properties-10.xhtml
-rw-rw-r-- 1 maarten 7673 Nov 4 20:11 properties-11.xhtml
-rw-rw-r-- 1 maarten 8552 Nov 4 20:11 properties-12.xhtml

This is a non-root directory with content in it. It has symbolic links
to all the library files, so from any "content" file, any "library"
file will be in a ./X path, and from any library file, any other library
file will be in a ../X path.

Groetjes,
Maarten Wiltink
Jul 20 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1470
by: Shawn Modersohn | last post by:
Can someone give me the lowdown on the way these two browsers deal with the following <?xml version="1.0" encoding="UTF-8"?> <?xml-stylesheet type="text/css" href="datadump.css"?> <!DOCTYPE datadump > <datadump> <name> <first>&txt;</first> <last>&sig;</last>
12
2786
by: Peter Collinson | last post by:
Hi... My external style sheet for a 200+ page site is marked up as: BODY, P, TABLE, TD, DIV { background: #ffffff; font-style: normal; font-variant: normal; font-weight: normal; font-size: 1em;
6
3424
by: Christopher Benson-Manica | last post by:
Just FMI, if an external stylesheet is linked to a page (with <link>), will subsequent <style> tags override the values in the external stylesheet? -- Christopher Benson-Manica | I *should* know what I'm talking about - if I ataru(at)cyberspace.org | don't, I need to know. Flames welcome.
2
2252
by: Markus Ernst | last post by:
Hi I build a small content management system. I use different external stylesheets for the admin section and the frontend, called admin.css and frontend.css. Now I would like to preview some frontend stuff in the admin section. Is there a syntax for accessing a style from a different style sheet? For example:
7
2584
by: David Filmer | last post by:
Greetings. I want to localize a style definition to a portion of an HTML document, but use an external stylesheet. It seems that I can only do <style><!-- @import url(styles/my_style.css);--></style> and <link rel=stylesheet href=styles/my_style.css type=text/css> in the header, which applies to the entire HTML document and is NOT what I want to do. This does not seem to work: <span style = @import url('styles/my_style.css');>
26
3498
by: HarryO | last post by:
I created an external stylesheet file 'styles.css' and an html file that includes the line: <LINK REL="stylesheet" TYPE="text/css" HREF="styles.css" Both the .css file and the html file reside on my local PC. When I open the html file with IE6 the styles are not seen in the webpage. Everything looks fine if I upload the .css and html files to my web server. Any ideas on why the styles don't appear on my local PC?
7
1692
by: Dan Nash | last post by:
Hi I'm trying to create an external stylesheet for use in my Web App. It works fine, and I've got it linked and everything. The only problem is the "background-image" property isn't working. I've selected the iamge through VS, and its in the _images/ subdir. The code that VS created is as follows: background-image: url(_images/back.jpg) Yet it doesn't work. The image appears in the CSS style editor, but when I run my app in the...
2
1711
by: Billy Cousins | last post by:
Can anyone tell me how to programmatically read the values from a stylesheet that is linked into my asp.net app? I can read styles that are declared in the HTML code, but have not found a way to get to the external stylesheet. For example, I want to read the font-size and font-family from a class in the stylesheet.
1
4674
by: Michel Couche | last post by:
Hello, I am starting the development of a newsletter The use of the class MailMessage of System.Net.Mail is quite straightforward for usual contact forms but my question here is "How can I reference a CSS file in the header of my newsletter message ?" Here is where I am .... (1) I found a way to reference a web page in the body of the message (ref: http://www.systemwebmail.com/faq/3.2.aspx) Dim mail As New MailMessage()
0
9643
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10313
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10147
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9946
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7494
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6735
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5378
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5511
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3643
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.