Scootney Publishing has various lines of books, which cover a broad range of subjects: general fiction; literary fiction; genre fiction (such as science fiction and romance); software and other technical reference books; biography; and home-repair. One of the company's most successful ventures has been placing the first chapter or two of each of its books on the company's Web site, to encourage actual book sales.
The content of each book is represented as XML, and each line of books has its own XSLT style sheet. This allows literary novels to be presented one way, reference books another, and so on. However, Scootney's latest titlea novel, Synchronized Jammingis a weird amalgam of fictional, technical, and other content, marked up using combined elements of several editorial lines.
XML File (jamming.xml)
Here's a brief excerpt from the first chapter of Synchronized Jamming. The book's structure is a mix of common elements of fiction, literal HTML code, and musical annotation.
<?xml version="1.0"?> <?xml:stylesheet type="text/xsl" href="jamming.xsl"?> <novel copyright="2001" isbn="555000000X"> <title>Synchronized Jamming</title> <author>Kari Hensien</author> <chapter number="1"> <title>The Bleeding Edge</title> <epigraph><text>Any sufficiently advanced technology is indistinguishable from noise.</text><author>Canopy Rose</author><source>The Fusion Manifesto</source></epigraph> <para>Politics. Technology. Rock'n'roll. All you needed to know about the underground band known as Canopy Rose was right there in the first couple grafs of their so-called "Fusion Manifesto":</para> <markup_code><![CDATA[ <html> <head><title>Fused</title></head> <body> <p>Listen. You know as well as we do...</p> <p>... the sound of one hand jammin':</p> ]]></markup_code> <chord duration="4.5" units="seconds" voice="steel" vibrato="on"> <note>A</note> <note>C</note> </chord> <markup_code><![CDATA[ <p>Welcome to the block party. Welcome to the revolution.</p> </body> </html> ]]></markup_code> </chapter> </novel>
XSLT File (jamming.xsl)
The Scootney production department developed the initial version of the XSLT style sheet for this file to process all the fiction-related markup in Synchronized Jamming. It was derived from their standard fiction.xsl style sheet for converting novel excerpts to HTML.
This initial jamming.xsl style sheet provides template rules for all the common fictional content encountered in this excerpt. Other such content types will be added to the style sheet in subsequent topics in this section.
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="http://www.w3.org/TR/REC-html40"> <xsl:template match="novel"> <HTML> <HEAD> <TITLE>Excerpt: "<xsl:value-of select="title"/>," by <xsl:value-of select="author"/> </TITLE> <STYLE> * {font-family: Arial,Helvetica,Univers,sans-serif} pre {font-family: Courier New,Courier,monospace} </STYLE> </HEAD> <BODY> <h2>Excerpt:<br/> <em><xsl:value-of select="title"/></em></h2> <h3>by <xsl:value-of select="author"/></h3> <h6>Copyright <xsl:value-of select="@copyright"/> by <xsl:value-of select="author"/></h6> <h6>Scootney Publishing / ISBN <xsl:value-of select="@isbn"/></h6> <hr size="2" width="50%" align="left"/> <xsl:apply-templates /> </BODY> </HTML> </xsl:template> <xsl:template match="novel/title"> </xsl:template> <xsl:template match="novel/author"> </xsl:template> <xsl:template match="chapter"> <div style="width:50%"> <h2>Chapter <xsl:value-of select="@number"/>:<br/> <xsl:value-of select="title"/></h2> <xsl:apply-templates/> </div> </xsl:template> <xsl:template match="chapter/title"> </xsl:template> <xsl:template match="epigraph"> <div style="width:50%; float:right; margin:5; padding:5; background-color:silver; border-style:double; border-left-width:0; border-right-width:0"> <xsl:apply-templates/> </div> </xsl:template> <xsl:template match="epigraph/text"> <div> <em><value-of select="."/></em> <xsl:apply-templates/> </div> </xsl:template> <xsl:template match="epigraph/author"> -- <xsl-value-of select="."/> <xsl:apply-templates/> </xsl:template> <xsl:template match="epigraph/source"> (<em><xsl:value-of select="."/></em>) </xsl:template> <xsl:template match="para"> <p><xsl:value-of select="."/></p> </xsl:template> </xsl:stylesheet>
Formatted Output
The initial XSLT file displays the content of the fiction-related elements. It does not, however, display content from computer-related and music-related elements.
The following topic, Using <xsl:include> to Insert an XSLT File, alters the XSLT file to make it more appropriate for the unusual content of the XML file.