XSLT for adding a different CSS stylesheet per page
This is an open discussion with 2 replies, filed under XSLT.
Search
The simplest is to use an if statement in your master.xsl file. Inside the head where you want to include the CSS, use:
<xsl:if test="$current-page='whatwedo'"> <link type="text/css" href="..." rel="stylesheet" media="all" /> </xsl:if>
The alternative is slightly more complex, but allows easier per-page control. In the master.xsl define an empty template:
<xsl:template name="css-includes"/>
Then in the head where you want to include your CSS, call this template:
<xsl:call-template name="css-includes"/>
By default this won't write anything, because the css-includes
template doesn't return anything. But inside your whatwedo
page you can redefine this template so that it does output something. In your page:
<xsl:call-template name="css-includes"> <link type="text/css" href="..." rel="stylesheet" media="all" /> </xsl:call-template>
But if option #1 works, then use that to save confusion in six months time :-)
Nick
Thanks so much. As usual I was doing the right thing but had the syntax wrong. I had {} curly brackets round the $current-page. My excuse is that I'm supposed to be the designer at www.atomised.coop but somehow my two programming colleagues run for the hills when XSLT is mentioned.
Lifesaver. Glad this post is here for a refresher in 6 months.
Cheers AL
Create an account or sign in to comment.
Hi there,
Sorry for these newbie questions. Did one site in 1.7 and then 6 months later it's like I've never seen XSLT before. I want to include a css stylesheet on only one page. So IF page is 'whatwedo' include example.css how do I do that? I can't seem to work it out?
(Sorry not a programmer!)
Help much appreciated
Kind regards AL