Embedding a CSS style sheet within a generated SVG file

Discussion in 'XML' started by FC, Sep 30, 2003.

  1. FC

    FC Guest

    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
    FC, Sep 30, 2003
    #1
    1. Advertising

  2. FC wrote:

    >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
    --
    SVG - Learning By Coding
    <http://www.datenverdrahten.de/svglbc/>
    Thomas Meinike, Oct 1, 2003
    #2
    1. Advertising

  3. FC

    FC Guest

    "Thomas Meinike" <> wrote in message
    news:...
    > FC wrote:
    >
    > >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
    > --
    > SVG - Learning By Coding
    > <http://www.datenverdrahten.de/svglbc/>



    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
    FC, Oct 1, 2003
    #3
  4. FC wrote:

    >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
    --
    SVG - Learning By Coding
    <http://www.datenverdrahten.de/svglbc/>
    Thomas Meinike, Oct 1, 2003
    #4
  5. FC

    FC Guest

    "Thomas Meinike" <> wrote in message
    news:...
    > FC wrote:
    >
    > >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
    > --


    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
    FC, Oct 1, 2003
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?Q2FtbWllIFdhdHNvbg==?=

    CSS style sheet not showing correctly on the server

    =?Utf-8?B?Q2FtbWllIFdhdHNvbg==?=, Nov 28, 2005, in forum: ASP .Net
    Replies:
    5
    Views:
    908
    =?Utf-8?B?Q2FtbWllIFdhdHNvbg==?=
    Nov 29, 2005
  2. Raphael Goubet

    Embedding SVG within XHTML

    Raphael Goubet, Feb 11, 2004, in forum: XML
    Replies:
    5
    Views:
    2,598
    Thomas Meinike
    Feb 25, 2004
  3. Arne Nordmann
    Replies:
    0
    Views:
    512
    Arne Nordmann
    Jun 28, 2004
  4. Replies:
    0
    Views:
    509
  5. Utada P.W. SIU

    Cannot using style sheet inside ASP generated Excel

    Utada P.W. SIU, Oct 4, 2004, in forum: ASP General
    Replies:
    1
    Views:
    270
    Ray Costanzo [MVP]
    Oct 4, 2004
Loading...

Share This Page