css in xsl document - css

how do i implement css in xsl file? i tried this:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<link rel="stylesheet" type="text/css" href="dxsl.css"/>
<xsl:output method="html" />
but it threw the error:
XSLTProcessor::importStylesheet(): Found a top-level element link with null namespace URI
and
Warning: XSLTProcessor::transformToXml(): No stylesheet associated to this object

Your html (link tag) must be inside an xsl:template. The xsl:template must be inside an xsl:stylesheet.
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" />
<xsl:template match="/*//*[1]">
<link rel="stylesheet" type="text/css" href="dxsl.css"/>
</xsl:template>
</xsl:stylesheet>

If I understand you correctly, you wish for the output to have a particular stylesheet?
XSL is a language used to transform XML from one format to another (in a sense it's like applying a css stylesheet). What would happen in a typical use case is that you would take some xml file and use XSL to transform it, say to XHTML. In this output, you can include a stylesheet using the link element if you wanted, but XSL doesnt really make use of CSS as such. (So basically, try putting the CSS in the XSL as part of the transformation to have the XHTML output use it.)
If this is an XML document you simply need to include the reference to the XSL and it should handle the transformation for you automatically.

'link' is a HTML element and you're trying to use it as an XML one. XSL modifies input into another document. You don't use CSS in an XSL file. You insert it into an (X)HTML file and apply it there.

As another answer said, the link must be generated by the transform. Here's an example that generates a small HTML doc with link to CSS from a simple xml doc. The css path comes from the data as well.
Try this

Related

Why does XHTML not work outside with a prefix?

To my eyes, this should be a valid XHTML document:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<a:html xmlns:a="http://www.w3.org/1999/xhtml">
<a:head>
<a:title>Document title</a:title>
</a:head>
<a:body>
<a:h1>Hello World!</a:h1>
</a:body>
</a:html>
However, it is not handled like XHTML by neither Firefox nor Internet Explorer, instead showing as text (with tags not visible). If I remove the namespace prefix…
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Document title</title>
</head>
<body>
<h1>Hello World!</h1>
</body>
</html>
… it is rendered fine. I would have thought that both documents are semantically equal. Why does the first one not work?
You have to make sure that browsers get the hint to interpret the document as application/xhtml+xml (or possibly one of the other XML MIME types) instead of text/html.
On a server, you can achieve this by sending the corresponding Content-Type HTTP header:
Content-Type: application/xhtml+xml
Locally, you can typically achieve this by using .xhtml instead of .html as file extension (but this might depend on your system).

Namespace problems in XSL transformation of XHTML

Whilst transforming XHTML to XHTML with XSL I have a problem with namespaces. Consider as an example input:
<!DOCTYPE html SYSTEM "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><title>Test</title></head>
<body>
<p>Remove this</p>
</body>
</html>
Then the following transformation does not work (e.g. does not remove the <p />):
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="#*|node()" name="copy">
<xsl:copy><xsl:apply-templates select="#*|node()" /></xsl:copy>
</xsl:template>
<xsl:template match="p" />
</xsl:stylesheet>
But this one does:
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xhtml="http://www.w3.org/1999/xhtml">
<xsl:template match="#*|node()" name="copy">
<xsl:copy><xsl:apply-templates select="#*|node()" /></xsl:copy>
</xsl:template>
<xsl:template match="xhtml:p" />
</xsl:stylesheet>
My problem and question is: How can I change the XSLT so that I do not have to add prefixes to all the XHTML elements and it still get to match them? From what I tried so far, adding a default namespace like <xsl:stylesheet xmlns="http://www.w3.org/1999/xhtml" /> does not achieve this.
Thanks for your help!
How can I change the XSLT so that I do not have to add prefixes to all the XHTML elements and it still get to match them?
This is possible, but I would recommens defining the namespace and using the preefix in referring to elements in this namespace:
<xsl:template match="*[local-name()='p']" />
Warning:
This technique can be safe only if it is guaranteed that there arent two elements with the same local-name() but in different namespaces.

Add conditional css style sheet to xpage

Is it possible to add a conditional style sheet to an xpage.
Done like this in html:
<!--[if lt IE 8]><link rel="stylesheet" href="../../blueprint/ie.css" type="text/css" media="screen, projection"><![endif]-->
Though about adding with computed field set to HTML and code javascript like:
return '<!--[if lt IE 8]><link rel=\"stylesheet\" href=\"../../blueprint/ie.css\" type=\"text/css\" media=\"screen, projection\"><![endif]-->'
but then it would be included in the body of page, not the header with the other style sheets.
Need for a proof of concept putting together using http://blueprintcss.org.
an Xpage theme would be great for this. There is an example included with the notes install.
go to C:\ Notes directory \xsp\nsf\themes
make a copy of webStandard.theme, rename is webStandard.xml and open in an editor of your choice, this will show you a lot of examples of what a theme can do. Apply attributes, add resources, compute these via expressions etc.
Snippet:
<resource rendered="#{javascript:context.isDirectionRTL()}">
<content-type>text/css</content-type>
<href>/.ibmxspres/global/theme/webstandard/xspRTL.css</href>
</resource>
<!-- IE Specific -->
<resource rendered="#{javascript:context.getUserAgent().isIE(0,6)}">
<content-type>text/css</content-type>
<href>/.ibmxspres/global/theme/webstandard/xspIE06.css</href>
</resource>
<resource rendered="#{javascript:context.getUserAgent().isIE(7,8)}">
<content-type>text/css</content-type>
<href>/.ibmxspres/global/theme/webstandard/xspIE78.css</href>
</resource>
You can use the rendered property with SSJS to show an element for IE only:
rendered="#{javascript:context.getUserAgent().isIE()}"
Then your CSS ressource will only added to the generated HTML response if a XPage is opened with Internet Explorer.
EDIT:
In your case this should fit your requirements:
<xp:this.resources>
<xp:styleSheet href="../../blueprint/ie.css"
rendered="#{javascript:context.getUserAgent().isIE(0,7)}"
media="screen, projection">
</xp:styleSheet>
</xp:this.resources>

Styling velocity markup with css in confluence 4.0

I have written a confluence macro. It uses velocity to generate html table. How can I style this markup with css if I don't use <html> and <head> tags in my velocity model. I have tried to do as in this example but id doesn't work(I mean it takes no effect and there is no css resource file that I have specified inclusion on the code of result page of macro)
if i understand you correctly
you need to add links on your css files to atlasian-plugin.xml for example
<atlassian-plugin name='Just name' key='com.your.path.to.lib'
plugins-version="2">
<resource type="download" name="style.css" location="css/style.css">
<property key="content-type" value="text/css"/>
</resource>
</atlassian-plugin>
after that you need to add this link to the top of your velocity template
<link rel="stylesheet" href="$req.contextPath/com.your.path.to.lib/style.css"
type="text/css"/>

Using XSLT to get all the get all the elements out of an xhtml file

I have an xhtml file that I'm attempting to transform such that:
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1 plus MathML 2.0//EN" "http://www.w3.org/TR/MathML2/dtd/xhtml-math11-f.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>yada</title>
<meta.....>
</head>
<body>
<p>Something</p>
<p>awesome</p>
</body>
</html>
becomes a
<title>yada</title>
<meta.....>
<p>Something</p>
<p>awesome</p>
The key thing that I'm getting at is that the <head> and <body> tags are removed from the document. I don't want to run this through sed or awk to remove them.
Everything that I've tried either has the whole thing in html or converts it all into pure text.
Background on problem: I've got a backup of my blog written in multimarkdown, I'm hoping to put them into different format but I need to get over this issue first.
Note: I started off with the identity template.
something like this? (bear with me, its been ages since I've done XSL actively)
<xsl:for-each select="head">
<xsl:copy-of select="."/>
</xsl:for-each>
<xsl:for-each select="body">
<xsl:copy-of select="."/>
</xsl:for-each>
Sounds like you want the identity transform for everything below html and body:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/html|/html/head|/html/body">
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="#*|node()">
<xsl:copy>
<xsl:apply-templates select="#*|node()"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
Are you sure this isn't the usual namespace problem? Does the input really look like you showed us, or did you leave out the namespaces because you didn't realise they made all the difference?

Resources