Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <xsl:stylesheet
- version="1.0"
- xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
- >
- <!-- this automagically creates the <meta http-equiv="Content-Type"> element! -->
- <xsl:output
- method="html"
- version="4.0"
- doctype-public="-//W3C//DTD HTML 4.01//EN"
- doctype-system="http://www.w3.org/TR/html4/loose.dtd"
- encoding="utf-8"
- indent="yes"
- />
- <!--
- this (/*) eats the document element (tstmt), which would otherwise be
- copied by the identiy template below. Make sure there is a specific
- template for everything you don't want to show up in the output as it is!
- -->
- <xsl:template match="/*" >
- <html>
- <head>
- <title>Book</title>
- <!-- no <meta http-equiv="Content-Type"> here! -->
- </head>
- <body>
- <xsl:apply-templates select="*" />
- </body>
- </html>
- </xsl:template>
- <!-- h1 elements -->
- <xsl:template match="title">
- <h1 class="{name()}"><xsl:apply-templates /></h1>
- </xsl:template>
- <!-- h2 elements -->
- <xsl:template match="title2|bktlong|chtitle">
- <h2 class="{name()}"><xsl:apply-templates /></h2>
- </xsl:template>
- <!-- h3 elements -->
- <xsl:template match="bktshort">
- <h3 class="{name()}"><xsl:apply-templates/></h3>
- </xsl:template>
- <!-- wrap certain elements in a div with their name as the CSS class -->
- <xsl:template match="coverpg|subtitle|titlepg|preface|ptitle|ptitle0|bookcoll|book|bksum|chapter|chsum">
- <!-- the following is 'true' for nodes that do not directly contain data -->
- <xsl:variable
- name = "containsStructureOnly"
- select = "count(self::coverpg | self::titlepg | self::bookcoll) > 0"
- />
- <!-- the following is 'true' should have a comment -->
- <xsl:variable
- name = "needsClosingComment"
- select = "count(self::subtitle | self::titlepg | self::preface | self::bookcoll | self::book) > 0"
- />
- <!-- the following is 'true' should have a counted id -->
- <xsl:variable
- name = "needsHtmlId"
- select = "count(self::book) > 0"
- />
- <!-- make a <div> with the correct class (you might have to adapt your CSS in some cases -->
- <div class="{name()}">
- <xsl:if test="$needsHtmlId">
- <xsl:attribute name="id">
- <xsl:value-of select="concat(name(), '-', position())" />
- </xsl:attribute>
- </xsl:if>
- <xsl:choose>
- <xsl:when test="$containsStructureOnly">
- <!-- in structure-only nodes we just look at the child elements -->
- <xsl:apply-templates select="*" />
- </xsl:when>
- <xsl:otherwise>
- <!-- in the other nodes we apply templates to everything there is -->
- <xsl:apply-templates />
- </xsl:otherwise>
- </xsl:choose>
- </div>
- <xsl:if test="$needsClosingComment">
- <xsl:comment>
- <xsl:text> End of <div class="</xsl:text>
- <xsl:value-of select="name()" />
- <xsl:text>"> </xsl:text>
- </xsl:comment>
- </xsl:if>
- </xsl:template>
- <xsl:template match="v">
- <p class="verse"><xsl:apply-templates/></p>
- </xsl:template>
- <!-- retain bold, italic, underline, paragrapth tags -->
- <xsl:template match="B|b|I|i|U|u|P|p">
- <!-- lowercase names look better in HTML -->
- <xsl:element name="{translate(name(), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz')}">
- <xsl:apply-templates />
- </xsl:element>
- </xsl:template>
- </xsl:stylesheet>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement