XML/XSLT/CSS: Include CSS in XSLT?

We want to include CSS information (.css) in XSLT for presentation in (X)HTML.
How to?
go4javaAsked:
Who is Participating?
 
Geert BormansInformation ArchitectCommented:
Hi go4java,

You can just stuff your CSS in your result document as you would do with a static HTML file

here is an example

test XML
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet href="mystyle.xsl" type="text/xsl"?>
<test>
    <elemA>This should be blue</elemA>
    <elemB>This should be green</elemB>
</test>

XSLT
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:template match="/">
    <html>
        <head>
            <style>
                .blue {background-color: blue;}
                .green {background-color: green;}
            </style>
        </head>
        <body>
            <h1>backgrounds</h1>
            <xsl:apply-templates/>
        </body>
    </html>
</xsl:template>
    <xsl:template match="elemA">
        <p class="blue"><xsl:value-of select="."/></p>
    </xsl:template>
    <xsl:template match="elemB">
        <p class="green"><xsl:value-of select="."/></p>
    </xsl:template>
</xsl:stylesheet>

<link> is as easy

Cheers!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.