Subject: RE: [xsl] Extending Xhtml2fo.xsl to handle CLASS attributes From: Graham Hannington <Ghannington@xxxxxxx> Date: Tue, 17 Dec 2002 13:43:50 -0000 |
I've begun work on handling the CLASS attributes a *slightly* better way than I described in my previous note: <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:css="http://www.csl.com/css" exclude-result-prefixes="css"> <css:stylesheet> <rule selector="span.note">font-weight: bold;</rule> <rule selector="span.normal">font-weight: normal;</rule> </css:stylesheet> . . . <xsl:template name="process-class"> <xsl:param name="element"/> <xsl:param name="class"/> <xsl:variable name="selector"> <xsl:choose> <xsl:when test="$class"> <xsl:value-of select="concat($element, '.', $class)" /> </xsl:when> <xsl:otherwise> <xsl:value-of select="$element" /> </xsl:otherwise> </xsl:choose> </xsl:variable> <xsl:variable name="rule" select="document('')/xsl:stylesheet/css:stylesheet/rule[@selector = $selector]" /> <xsl:if test="$rule"> <xsl:attribute name="style"><xsl:value-of select="$rule" /></xsl:attribute> </xsl:if> </xsl:template> (The code above is in the XSL stylesheet that I use prior to Xhtml2fo.xsl.) The process-class template replaces: <p><span class="note">Programmers:</span> Do this.</p> with <p><span class="note" style="font-weight: bold;">Programmers:</span> Do this.</p> Some limitations: - Only one selector per rule: I'd like to be able to specify something like selector="span.note, span.object, span.name", so the same attributes can apply to many classes, as they do in a CSS file. - The rules don't cascade (I'm less upset about this). - This syntax doesn't yet handle "behaviors" (although I'm thinking that I could add a "template" attribute to the <rule> tag, that I could use in the process-class template to call a named template that would do the necessary processing). I'd welcome advice on any of this. XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] Extending Xhtml2fo.xsl to han, Graham Hannington | Thread | RE: [xsl] Extending Xhtml2fo.xsl to, Graham Hannington |
RE: [xsl] Fibonacci & XSL, bryan | Date | [xsl] Updating XML, Marko Petersen |
Month |