Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

Tomalak

By: a guest on Nov 11th, 2009  |  syntax: XML  |  size: 3.48 KB  |  views: 46  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
This paste has a previous version, view the difference. Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. <xsl:stylesheet
  2.  version="1.0"
  3.  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  4. >
  5.   <!-- this automagically creates the <meta http-equiv="Content-Type"> element! -->
  6.   <xsl:output
  7.    method="html"
  8.    version="4.0"
  9.    doctype-public="-//W3C//DTD HTML 4.01//EN"
  10.    doctype-system="http://www.w3.org/TR/html4/loose.dtd"
  11.    encoding="utf-8"
  12.    indent="yes"
  13.  />
  14.  
  15.   <!--
  16.    this (/*) eats the document element (tstmt), which would otherwise be
  17.    copied by the identiy template below. Make sure there is a specific
  18.    template for everything you don't want to show up in the output as it is!
  19.  -->
  20.   <xsl:template match="/*" >
  21.     <html>
  22.       <head>
  23.         <title>Book</title>
  24.         <!-- no <meta http-equiv="Content-Type"> here! -->
  25.       </head>
  26.       <body>
  27.         <xsl:apply-templates select="*" />
  28.       </body>
  29.     </html>
  30.   </xsl:template>
  31.  
  32.   <!-- h1 elements -->
  33.   <xsl:template match="title">
  34.     <h1 class="{name()}"><xsl:apply-templates /></h1>
  35.   </xsl:template>
  36.  
  37.   <!-- h2 elements -->
  38.   <xsl:template match="title2|bktlong|chtitle">
  39.     <h2 class="{name()}"><xsl:apply-templates /></h2>
  40.   </xsl:template>
  41.  
  42.   <!-- h3 elements -->
  43.   <xsl:template match="bktshort">
  44.     <h3 class="{name()}"><xsl:apply-templates/></h3>
  45.   </xsl:template>
  46.  
  47.   <!-- wrap certain elements in a div with their name as the CSS class -->
  48.   <xsl:template match="coverpg|subtitle|titlepg|preface|ptitle|ptitle0|bookcoll|book|bksum|chapter|chsum">
  49.     <!-- the following is 'true' for nodes that do not directly contain data -->
  50.     <xsl:variable
  51.      name   = "containsStructureOnly"
  52.      select = "count(self::coverpg | self::titlepg | self::bookcoll) &gt; 0"
  53.    />
  54.     <!-- the following is 'true' should have a comment -->
  55.     <xsl:variable
  56.      name   = "needsClosingComment"
  57.      select = "count(self::subtitle | self::titlepg | self::preface | self::bookcoll | self::book) &gt; 0"
  58.    />
  59.     <!-- the following is 'true' should have a counted id -->
  60.     <xsl:variable
  61.      name   = "needsHtmlId"
  62.      select = "count(self::book) &gt; 0"
  63.    />
  64.     <!-- make a <div> with the correct class (you might have to adapt your CSS in some cases -->
  65.     <div class="{name()}">
  66.       <xsl:if test="$needsHtmlId">
  67.         <xsl:attribute name="id">
  68.           <xsl:value-of select="concat(name(), '-', position())" />
  69.         </xsl:attribute>
  70.       </xsl:if>
  71.       <xsl:choose>
  72.         <xsl:when test="$containsStructureOnly">
  73.           <!-- in structure-only nodes we just look at the child elements -->
  74.           <xsl:apply-templates select="*" />
  75.         </xsl:when>
  76.         <xsl:otherwise>
  77.           <!-- in the other nodes we apply templates to everything there is -->
  78.           <xsl:apply-templates />
  79.         </xsl:otherwise>
  80.       </xsl:choose>
  81.     </div>
  82.     <xsl:if test="$needsClosingComment">
  83.       <xsl:comment>
  84.         <xsl:text> End of &lt;div class="</xsl:text>
  85.         <xsl:value-of select="name()" />
  86.         <xsl:text>"&gt; </xsl:text>
  87.       </xsl:comment>
  88.     </xsl:if>
  89.   </xsl:template>
  90.  
  91.   <xsl:template match="v">
  92.     <p class="verse"><xsl:apply-templates/></p>
  93.   </xsl:template>
  94.  
  95.   <!-- retain bold, italic, underline, paragrapth tags -->
  96.   <xsl:template match="B|b|I|i|U|u|P|p">
  97.     <!-- lowercase names look better in HTML -->
  98.     <xsl:element name="{translate(name(), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz')}">
  99.       <xsl:apply-templates />
  100.     </xsl:element>
  101.   </xsl:template>
  102.  
  103. </xsl:stylesheet>