Embedding a CSS style sheet within a generated SVG file

F

FC

Hello folks,
I was wondering if there any other method of achieving the following:

I have a XSL transformation outputting a SVG document.
For reasons too long to explain here, I must embed a CSS style sheet inside
a <style> element in the SVG output document using a CDATA block.
The CSS stylesheet is not an xml document, therefore I cannot open it using
the document function (I suppose, I didn't even try frankly).
In order to work around the problem, I created a "parallel" xml version of
the CSS stylesheet, just embedding everything within a <css> element, plus
the usual xml header.
In this fashion I can open it with document and extract the text node
belonging to <css> and copy it to the output document.

This rather cumbersome method forces me to re-create the fake css every time
I modify the real stylesheet, so I was just asking myself if it is a
by-product of too many late hours or just an honest solution.

Here is the code:

<xsl:if test="$embed=1">

<style type="text/css">

<xsl:text disable-output-escaping="yes">&lt;![CDATA[</xsl:text>

<xsl:value-of select="document(concat($css,'.xml'))/css/text()"/>

<xsl:text disable-output-escaping="yes">]]&gt;</xsl:text>

</style>

</xsl:if>


Thanks for your advice,
Flavio
 
T

Thomas Meinike

FC said:
In order to work around the problem, I created a "parallel" xml version of
the CSS stylesheet, just embedding everything within a <css> element, plus
the usual xml header.
In this fashion I can open it with document and extract the text node
belonging to <css> and copy it to the output document.

You can create a processing instruction for including the external
stylesheet:

<xsl:processing-instruction name="xml-stylesheet">
href="<xsl:value-of select="..."/>" type="text/css"
</xsl:processing-instruction>

cu, Thomas
 
F

FC

Thomas Meinike said:
You can create a processing instruction for including the external
stylesheet:

<xsl:processing-instruction name="xml-stylesheet">
href="<xsl:value-of select="..."/>" type="text/css"
</xsl:processing-instruction>

cu, Thomas


Well, thanks, I know I can do it, but the story goes that I can't use that
method because the server where these pages are located does not send the
correct MIME type and the page is displayed as plain text.
I cannot change the situation as I am not the webmaster and these guys want
to get paid for the "service".
If you try to work around the problem by embedding the svg page inside
<object> (because it allows to specify the MIME type in the type attribute)
then you'll find out soon that it doesn't work properly (IE 5.5, IE 6) when
you use a reference to a CSS stylesheet, but it does work when you include
the CSS as a CDATA block.

Indeed my XSLT program takes a parameter specifying if the CSS must be
linked or included, so when it is linked, it works exactly as you suggested.

Bye,
Flavio
 
T

Thomas Meinike

FC said:
If you try to work around the problem by embedding the svg page inside
<object> (because it allows to specify the MIME type in the type attribute)
then you'll find out soon that it doesn't work properly (IE 5.5, IE 6) when
you use a reference to a CSS stylesheet, but it does work when you include
the CSS as a CDATA block.

Try to use an absolute URI refererence http://.../your.css

My XSLT/SVG application
<http://www.et.fh-merseburg.de/person/meinike/mspecsvg/> runs with
this method using xsl:processing-instruction.

cu, Thomas
 
F

FC

Thomas Meinike said:
Try to use an absolute URI refererence http://.../your.css

My XSLT/SVG application
<http://www.et.fh-merseburg.de/person/meinike/mspecsvg/> runs with
this method using xsl:processing-instruction.

cu, Thomas
--

Ok, thank you again, perhaps I didn't stress enough the subject of my
request.
I am interested in knowing how to include a non-xml document into an xml
document by means of xslt.
So the origin of this request can be neglected for a while.

I am quite satisfied with the method I found, it works when I need to
perform tests locally and it works remotely, I am not bound to an active
Internet connection just to retrieve a stylesheet.
Moreover, generally speaking, the relative URI to the stylesheet does work
correctly with IFRAME, the problem is just with "my" server who doesn't
handle the correct MIME and I haven't got the privileges to add it.

Cheers,
Flavio
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,815
Latest member
treekmostly22

Latest Threads

Top