Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 24th, 2014, 12:38 PM
Authorized User
 
Join Date: Mar 2014
Posts: 26
Thanks: 2
Thanked 0 Times in 0 Posts
Default linking CSS file to XSL file

Hello,

How can I link my xsl file to a css file? I have a stylesheet file: style.css, and the usual method of linking it to an HTML page doesn't seem to work in XSL. What I mean by the "usual method" is this:

<link href="style.css" rel="stylesheet" type="text/css"/>

But when I try to run the report, it tells me: "Top-level element 'link' may not have a null namespace URI."

I'm not sure what this means. I tried putting in a uri as follows: uri="style.css", but this didn't do anything.

How does one link an XSL file to a CSS file?
 
Old March 24th, 2014, 01:08 PM
Friend of Wrox
 
Join Date: Nov 2007
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
Default

If you want to have your XSLT create HTML where the HTML uses your CSS stylesheet then you can do that by making sure the XSLT creates a HTML "link" element in the "head" section of the result document e.g.
Code:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">

<xsl:template match="/">
  <html>
     <head>
       <title>Example</title>
       <link href="style.css" rel="stylesheet" type="text/css"/>
     </head>
     <body>
         <h1>Example</h1>
         <xsl:apply-templates/>
     </body>
  </html>
</xsl:template>

...
</xsl:stylesheet>
That is the way I can think of that makes sense and is doable. Trying to put a HTML link directly into a stylesheet to "link CSS file to XSL file" does not make sense to me, you would need to explain what you want to achieve that way.
__________________
Martin Honnen
Microsoft MVP (XML, Data Platform Development) 2005/04 - 2013/03
My blog
 
Old March 24th, 2014, 01:57 PM
Authorized User
 
Join Date: Mar 2014
Posts: 26
Thanks: 2
Thanked 0 Times in 0 Posts
Default

Sorry Martin, but that doesn't quite seem to work for some reason.

What I'm trying to do is style my tables, rows, cells, and cell content using a CSS file. In my template, I have something like this:

<xsl:template name="myTemplate">

<table class="myCSSClass">
...
</table>

</xsl:template>

So, in other words, I have a table and I want to apply the style in style.css to the table (particularly, the myCSSClass style class). I'm expecting it to work just like it does in HTML, but maybe this is my mistake.
 
Old March 24th, 2014, 02:11 PM
Friend of Wrox
 
Join Date: Nov 2007
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
Default

If your XSLT creates HTML output then I think my suggestion does work, as long as you create a complete HTML document where you create a head section in which you can place the "link" element.

You seem to want to create a "table" result element, is that a HTML table? If so why can't you use my suggestion to make sure your XSLT as well creates a "html" root element with a "head" section where you place the "link" element?

If you don't want to create HTML then don't expect the HTML mechanisms like "class" attribute or "link" element to work.
__________________
Martin Honnen
Microsoft MVP (XML, Data Platform Development) 2005/04 - 2013/03
My blog
 
Old March 25th, 2014, 05:06 AM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

The key is that you don't apply the CSS to your XSLT - there is no way to do that.

What you are doing is applying the XSLT to your input XML, which outputs HTML. You are including a stylesheet reference in that output HTML, which is then being applied, by the browser, to the rendered HTML.
__________________
/- Sam Judson : Wrox Technical Editor -/

Think before you post: What have you tried?





Similar Threads
Thread Thread Starter Forum Replies Last Post
help needed for code to convert the plist to xml file and xml file to plistusing xsl venkat880 BOOK: Beginning XSLT and XPath : Transforming XML Documents and Data 0 August 4th, 2011 07:22 AM
No such file or directory error for wrong linking awotta BOOK: Professional Assembly Language 1 January 10th, 2010 07:44 AM
Call or linking to external .jar file tony_s Java Basics 0 December 16th, 2006 05:20 PM
linking to external vbscript file fs22 Javascript 2 April 20th, 2004 03:38 AM
XSL Transform with xsl string NOT xsl file skin XSLT 0 June 16th, 2003 07:30 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.