Combining HTML/FO StyleSheets (Indirection/Abstraction
Greetings, -- Sorry this is so long -- I have developing some XSLT files to translate an XML document to HTML and then moved onto creating XSL:FO translation of the same document. I noticed the bulk of the complex operations are the same or very similar for both style sheets and in order to avoid inconsistances I like to merge the two sheets. Are there guidelines anywhere on developing such merged sheets? After slaving way at the problem I'll discuss below and coming up with several non-working solutions, I was wondering "Do people create intermediate markup languages to ease the generation of both HTML and FO?" By this I mean do people generate and intermediate format (XML) which has all of the complex processing completed, and then have trivial conversion style sheets from that format to HTML or XSL:FO as appropriate? ((Example: intermediate tag like <paragraph> -> <p> or <fo:block> depending on the desired output format)) ---------------------------------------------------------------------- Anyway on to the actual problem. I have a tag I would like to generate additional document content for, but I would like to be able to include a level of indirection in that generation to make it general purpose (ie not HTML or XSL:FO specific) I'll use a concrete example so it makes some sense :-) But the problem occurs in other forms in the processing as well. The XML ======= <versioninfo mode="RCS" filename="$RCSfile: Software.xml,v $" filerevision="$Revision: 1.12 $" filerevisiondate="$Date: 2002/01/29 12:24:53 $" timezone="GMT" /> Note: I have additional named templates to extract just the actual information out of these RCS tags :-) The Problem =========== I would like to generate a simple paragraph whose contents are in italics and in which the version number is in bold. Remember I'm trying to solve a general problem here so don't get caught in the specifics. Sample: Generated from RCS File Software.xml,v 1.12 2002/01/29 12:24:53 GMT. The paragraph above is all or partially in italics and the version number is in bold italics. OK. So as everyone can see this is not a complex task in either HTML or XSL:FO - but how do I generate text with a level of indirection to allow me to have high-level output-mode-independent style sheets? Solutions (or my failed attempts) ================================= The first thing I tried was to have named-templates called "MakeParagraph", "Inline-Italics" and "Inline-Bold" (as you can probably see this could be extended for most simple inline text formatting). Each determines the type of out desired and places the provided text (from with-param tag) inside the appropriate formatting constructs and returns the result. Each of these work in isolation!!! But if I try and nest the calls the tags (not the text) get stripped (seemingly at the stage of passing the parameter in with <with-param>. And just the result of nested calling is only the outer tags get generated in the output. Example: <xsl:call-template name="MakeParagraph"> <xsl:with-param name="contents"> <xsl:text>Text Here </xsl:text> <xsl:call-template name="Inline-Italics"> <xsl:with-param name="text"> <xsl:text>Italic Text Here </xsl:text> <xsl:call-template name="Inline-Bold"> <xsl:with-param name="text"> <xsl:text>Bold Italics Text Here</xsl:text> </xsl:with-param> </xsl:call-template> <xsl:text> More Just Italic Text Here</xsl:text> </xsl:with-param> </xsl:call-template> </xsl:with-param> </xsl:call-template> and in this case the greatly simplified HTML only named-templated <xsl:template name="MakeParagraph"> <xsl:param name="contents"/> <p> <xsl:value-of select="$contents"/> </p> </xsl:template> <xsl:template name="Inline-Italics"> <xsl:param name="text"/> <i> <xsl:value-of select="$text"/> </i> </xsl:template> <xsl:template name="Inline-Bold"> <xsl:param name="text"/> <b> <xsl:value-of select="$text"/> </b> </xsl:template> Result: ====== <p>Text Here Italic Text Here Bold Italics Text Here More Just Italic Text Here</p> Notice how the other tags have been stripped out of the result (this happens on all three XSLT processors I have - xsltproc,xalan,saxon) ANY THOUGHTS ???? Solution 2: Was to try and generate intermediate tags on the fly and have them stuffed back into the processing stream (thereby deferring HTML or XSL:FO generation) But I could not get this to work either and it seems against the design goals of XSLT to process on-the-fly generated markup recursively. ANY THOUGHTS ???? http://movies.yahoo.com.au - Yahoo! Movies - Vote for your nominees in our online Oscars pool. XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
PURCHASE STYLUS STUDIO ONLINE TODAY!
Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!
Download The World's Best XML IDE!
Accelerate XML development with our award-winning XML IDE - Download a free trial today!
Subscribe in XML format