mihai-rotaru

blog_post-to-docbook.xsl

Dec 31st, 2011
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
XML 5.14 KB | None | 0 0
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <xsl:stylesheet version="1.0"
  3.    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  4.    xmlns="http://docbook.org/ns/docbook"
  5.    >
  6.  
  7. <xsl:strip-space elements="*"/>
  8. <xsl:output version="1.0" encoding="utf-8" indent="yes"/>
  9.  
  10.     <!--~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~-->
  11.     <xsl:template match="/">
  12.     <article xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" version="5.0" xml:lang="en">
  13.         <xsl:apply-templates select="blog_post"/>
  14.     </article>
  15.     </xsl:template>
  16.  
  17.     <!--~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~-->
  18.     <xsl:template match="blog_post">
  19.         <xsl:apply-templates select="head"/>
  20.         <xsl:apply-templates select="body"/>
  21.     </xsl:template>
  22.  
  23.     <!--~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~-->
  24.     <xsl:template match="head">
  25.         <info>
  26.             <title><xsl:value-of select="title"/></title>
  27.             <author>
  28.                 <personname>
  29.                     <firstname><xsl:value-of select="author/name"/></firstname>
  30.                     <surname><xsl:value-of select="author/surname"/></surname>
  31.                 </personname>
  32.             </author>
  33.             <authorinitials>MR</authorinitials>
  34.            
  35.             <xsl:if test="tags/tag">
  36.                 <keywordset>
  37.                     <xsl:for-each select="tags/tag">
  38.                         <keyword><xsl:value-of select="."/></keyword>
  39.                     </xsl:for-each>
  40.                 </keywordset>
  41.             </xsl:if>
  42.  
  43.             <xsl:if test="date">
  44.                 <date><xsl:value-of select="date"/></date>
  45.             </xsl:if>
  46.  
  47.         </info>
  48.     </xsl:template>
  49.  
  50.     <!--~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~-->
  51.     <xsl:template match="body">
  52.        
  53.         <xsl:for-each select="node()">
  54.            
  55.             <xsl:choose>
  56.                 <xsl:when test="name()='code'">
  57.                     <screen>
  58.                         <xsl:value-of select="."/>
  59.                     </screen>
  60.                 </xsl:when>
  61.                
  62.                 <xsl:when test="name()='question' or name()='p' or name()='ul' or name()='img'">
  63.                     <xsl:apply-templates select="."/>
  64.                 </xsl:when>
  65.  
  66.                 <xsl:otherwise>
  67.                     <xsl:value-of select="."/>
  68.                 </xsl:otherwise>
  69.             </xsl:choose>
  70.  
  71.             </xsl:for-each>
  72.     </xsl:template>
  73.  
  74.     <!--~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~-->
  75.     <xsl:template match="question">
  76.         <p>
  77.             <xsl:value-of select="body/text()"/>
  78.             <xsl:text> [ </xsl:text>
  79.             <xsl:value-of select="selectedanswer"/>
  80.             <xsl:text> ] </xsl:text>
  81.         </p>
  82.         <xsl:apply-templates select="body/code"/>
  83.         <xsl:apply-templates select="options"/>
  84.         <p>
  85.             <xsl:value-of select="answer"/>
  86.         </p>
  87.         <hr/>
  88.     </xsl:template>
  89.  
  90.     <!--~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~-->
  91.     <xsl:template match="code">
  92.         <screen>
  93.             <xsl:value-of select="."/>
  94.         </screen>
  95.     </xsl:template>
  96.  
  97.     <!--~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~-->
  98.     <xsl:template match="img">
  99.         <mediaobject>
  100.             <imagedata></imagedata>
  101.         </mediaobject>
  102.     </xsl:template>
  103.  
  104.  
  105.     <!--~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~-->
  106.     <xsl:template match="ul">
  107.         <itemizedlist>
  108.         <xsl:for-each select="./li">
  109.             <listitem>
  110.                 <para>
  111.                     <xsl:value-of select="."/>
  112.                 </para>
  113.             </listitem>
  114.         </xsl:for-each>
  115.         </itemizedlist>
  116.     </xsl:template>
  117.  
  118.  
  119.     <!--~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~-->
  120.     <xsl:template match="options">
  121.         <ul>
  122.             <xsl:for-each select="./option">
  123.                 <li>
  124.                     <xsl:number format="a. " />
  125.                     <xsl:value-of select="."/>
  126.                 </li>
  127.             </xsl:for-each>
  128.         </ul>
  129.     </xsl:template>    
  130.  
  131.  
  132.     <!--~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~-->
  133.     <xsl:template match="p">
  134.         <para>
  135.             <xsl:for-each select="node()">
  136.  
  137.                 <xsl:choose>
  138.                    
  139.                     <xsl:when test="name() = 'em'">
  140.                         <emphasis><xsl:value-of select="."/></emphasis>
  141.                     </xsl:when>
  142.  
  143.                     <xsl:when test="name() = 'var'">
  144.                         <literal><xsl:value-of select="."/></literal>
  145.                     </xsl:when>
  146.  
  147.                     <xsl:when test="name() = 'ul'">
  148.                         <xsl:apply-templates select="."/>
  149.                     </xsl:when>
  150.                    
  151.                     <xsl:otherwise>
  152.                         <xsl:value-of select="."/>
  153.                     </xsl:otherwise>
  154.  
  155.                 </xsl:choose>
  156.  
  157.             </xsl:for-each>
  158.         </para>
  159.     </xsl:template>
  160.  
  161. </xsl:stylesheet>
Advertisement
Add Comment
Please, Sign In to add comment