Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Apr 15th, 2012  |  syntax: HTML  |  size: 5.61 KB  |  hits: 14  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  2.    xmlns="http://www.w3.org/1999/xhtml"
  3.    version="1.0">
  4.     <xsl:output method="xml"
  5.    doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN"
  6.    doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"
  7.    encoding="utf-8"
  8.    indent="yes"/>
  9.  
  10.     <!-- TODO customize transformation rules
  11.         syntax recommendation http://www.w3.org/TR/xslt
  12.    -->
  13.     <xsl:template match="/">
  14.         <html>
  15.             <head>
  16.                 <title> Addressbook </title>
  17.             </head>
  18.             <body>
  19.                
  20.                 <div>
  21.                     <h1>
  22.                         Addressbook
  23.                     </h1>
  24.                 </div>
  25.                
  26.                 <div>
  27.                     <strong>
  28.                         Quick links to people
  29.                     </strong>
  30.                 </div>
  31.                
  32.                 <div id="quicklist">
  33.                     <ul>
  34.                         <xsl:apply-templates mode="quicklist"/>
  35.                     </ul>
  36.                 </div>
  37.                
  38.                 <div id="content">
  39.  
  40.                         <xsl:apply-templates/>
  41.  
  42.                 </div>
  43.                
  44.             </body>
  45.         </html>
  46.     </xsl:template>
  47.  
  48.  
  49.     <xsl:template match="person" mode="quicklist">  
  50.             <xsl:if test="@id">
  51.                 <li>              
  52.                         <xsl:element name="a">
  53.                             <xsl:attribute name="href">#<xsl:value-of select="@id"/></xsl:attribute>
  54.                             <b>
  55.                                 <xsl:value-of select="firstname"/>
  56.                                 <xsl:text> </xsl:text>
  57.                                 <xsl:value-of select="surname"/>
  58.                             </b>
  59.                             <xsl:text> (</xsl:text>
  60.                             <xsl:value-of select="@id"/>
  61.                             <xsl:text>)</xsl:text>
  62.                         </xsl:element>                  
  63.                 </li>
  64.             </xsl:if>
  65.     </xsl:template>
  66.    
  67.     <xsl:template match="person">  
  68.         <xsl:if test="@id">
  69.             <div>
  70.                 <div>
  71.                    
  72.                     <hr/>
  73.                     <h2>
  74.                     <xsl:element name="a">
  75.                         <xsl:attribute name="name"><xsl:value-of select="@id"/></xsl:attribute>
  76.                        
  77.                             <xsl:value-of select="firstname"/>
  78.                             <xsl:text> </xsl:text>
  79.                             <xsl:value-of select="surname"/>
  80.                        
  81.                     </xsl:element>
  82.                     </h2>
  83.                 </div>
  84.                
  85.                 <div>
  86.                         <xsl:apply-templates select="e-mail"/>
  87.                 </div>
  88.                 <div>
  89.                         <xsl:apply-templates select="contacts"/>
  90.                 </div>
  91.             </div>
  92.            
  93.         </xsl:if>
  94.     </xsl:template>
  95.    
  96.     <xsl:template match="e-mail">  
  97.         <xsl:if test="not(.='')">
  98.             <div>
  99.                 <xsl:text>e-mail: </xsl:text>
  100.                 <xsl:element name="a">
  101.                     <xsl:attribute name="href">mailto:<xsl:value-of select="."/></xsl:attribute>                    
  102.                     <xsl:value-of select="."/>
  103.                 </xsl:element>
  104.             </div>
  105.         </xsl:if>        
  106.     </xsl:template>
  107.    
  108.     <xsl:template match="contacts">  
  109.         <div>
  110.             <xsl:choose>
  111.                 <xsl:when test="*">
  112.                     <xsl:choose>
  113.                         <xsl:when test="@visible = 'true'">
  114.                                 <div>
  115.                                   <xsl:apply-templates select="contact"/>
  116.                                 </div>
  117.                         </xsl:when>
  118.                         <xsl:otherwise>
  119.                             <em>
  120.                             Some contacts but not visible
  121.                             </em>
  122.                         </xsl:otherwise>
  123.                     </xsl:choose>
  124.                 </xsl:when>
  125.                 <xsl:otherwise>
  126.                     <em>
  127.                     No contacts            
  128.                     </em>
  129.                 </xsl:otherwise>
  130.             </xsl:choose>
  131.         </div>
  132.     </xsl:template>
  133.    
  134.     <xsl:template match="contact">  
  135.         <div>
  136.             <xsl:choose>
  137.                 <xsl:when test="@visible='false'">
  138.                     <em>
  139.                     An invisible contact
  140.                     </em>
  141.                 </xsl:when>
  142.                 <xsl:otherwise>
  143.                     <xsl:variable name="myIdVar" select="@person-ref"/>                  
  144.                     <xsl:variable name="myPersonVar" select="/address-book/person[@id=$myIdVar]"/>
  145.                     <xsl:apply-templates select="$myPersonVar" mode="list"/>        
  146.                 </xsl:otherwise>
  147.             </xsl:choose>
  148.         </div>
  149.     </xsl:template>
  150.    
  151.     <xsl:template match="person" mode="list">  
  152.             <xsl:if test="@id">
  153.                         <xsl:text>Contact: </xsl:text>
  154.                         <b>
  155.                             <xsl:value-of select="firstname"/>
  156.                             <xsl:text> </xsl:text>
  157.                             <xsl:value-of select="surname"/>
  158.                         </b>
  159.                         <xsl:text> (</xsl:text>
  160.                         <xsl:value-of select="@id"/>
  161.                         <xsl:text>)</xsl:text>
  162.             </xsl:if>
  163.     </xsl:template>
  164.  
  165.  
  166. </xsl:stylesheet>