Changeset 3150


Ignore:
Timestamp:
07/17/13 13:48:44 (11 years ago)
Author:
sanmai
Message:
  • Merge changes made with rev. 3133 in metadata/trunk/toolkit/xslt/cmdi2xhtml.xsl .
  • Adopt a clearer code style, with attributes on separate lines from their element.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • vlo/trunk/vlo_importer/src/main/resources/cmdi2xhtml.xsl

    r2846 r3150  
    11<?xml version="1.0" encoding="UTF-8"?>
    2 <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
     2<xsl:stylesheet
     3    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    34    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    45    xmlns:cmd="http://www.clarin.eu/cmd/"
     
    1819        cdata-section-elements="td"/>
    1920   
    20     <xsl:param name="prune_Components_branches_without_text_values" as="xs:boolean" select='false()'/>
    21    
    22 
    23     <xsl:template name="Component_tree" match="/CMD/Components">
    24         <xsl:param name="nodeset" as="element()+" select="/CMD/Components"/>
     21    <xsl:param
     22        name="prune_Components_branches_without_text_values"
     23        as="xs:boolean"
     24        select='false()'/>
     25
     26    <xsl:template
     27        name="Component_tree"
     28        match="/CMD/Components">
     29        <xsl:param
     30            name="nodeset"
     31            as="element()+"
     32            select="/CMD/Components"/>
    2533
    2634        <ul>
    27             <xsl:for-each select="$nodeset/element()">
    28                 <xsl:variable name="subnodes_text" select="fn:normalize-space(fn:string-join(descendant-or-self::element()/text(), ''))" as="xs:string+"/>
    29                 <xsl:if test="not($subnodes_text = '' and $prune_Components_branches_without_text_values)">
    30                     <xsl:variable name="nchildren" select="fn:count(child::element())"/>
     35            <xsl:for-each
     36                select="$nodeset/element()">
     37                <xsl:variable
     38                    name="subnodes_text"
     39                    select="fn:normalize-space(fn:string-join(descendant-or-self::element()/text(), ''))" as="xs:string+"/>
     40                <xsl:if
     41                    test="not($subnodes_text = '' and $prune_Components_branches_without_text_values)">
     42                    <xsl:variable
     43                        name="nchildren"
     44                        select="fn:count(child::element())"/>
    3145                     <li>
    3246                     
    3347                     <code class="node">
    34                          <xsl:value-of select="fn:concat(local-name(), ' ')"/>
    35                          <xsl:if test="count(@*) > 0">
     48                         <xsl:value-of
     49                             select="fn:concat(local-name(), ' ')"/>
     50                         <xsl:if
     51                             test="count(@*) > 0">
    3652                             <div class="attributes">
    37                                  <xsl:for-each select="@*">
    38                                      <xsl:value-of select="name()"/>="<xsl:value-of select="."/>"
     53                                 <xsl:for-each
     54                                     select="@*">
     55                                     <xsl:value-of
     56                                         select="name()"/>="<xsl:value-of select="."/>"
    3957                                 </xsl:for-each>
    4058                             </div>
     
    4361                   
    4462                     <xsl:choose>
    45                          <xsl:when test="$nchildren = 0">
     63                         <xsl:when
     64                             test="$nchildren = 0 and not(not(child::node()))">
    4665                             <!--<br /><br />-->
    4766                             <div class="Component_tree_node_content">
    48                                  <xsl:variable name="leaf_value" select="self::element()"                       as="xs:string"/>
    49                                  <xsl:variable name="HTTP_URL"   select="starts-with($leaf_value, 'http://')"   as="xs:boolean"/>
    50                                  <code class="leaf">
    51                                  <xsl:choose>
    52                                      <xsl:when test="$HTTP_URL">
    53                                          <a href="{$leaf_value}"><xsl:value-of select="$leaf_value"/></a>
    54                                      </xsl:when>
    55                                      <xsl:otherwise>                                   
    56                                              <xsl:value-of select="$leaf_value"/>                                         
    57                                      </xsl:otherwise>                                 
    58                                  </xsl:choose>
    59                                  </code>
     67                                <xsl:choose>
     68                                    <xsl:when
     69                                        test="self::element() castable as xs:string">
     70                                        <xsl:variable
     71                                            name="leaf_value"
     72                                            select="self::element() cast as xs:string"
     73                                            as="xs:string"/>                                         
     74                                        <xsl:variable
     75                                            name="is_URL"
     76                                            select="starts-with($leaf_value, 'http://') or starts-with($leaf_value, 'https://')"
     77                                            as="xs:boolean"/>
     78                                        <code class="leaf">
     79                                            <xsl:choose>
     80                                                <xsl:when
     81                                                    test="$is_URL">
     82                                                    <a href="{$leaf_value}">
     83                                                        <xsl:value-of
     84                                                            select="$leaf_value"/>
     85                                                    </a>
     86                                                </xsl:when>
     87                                                <xsl:otherwise>                                   
     88                                                    <xsl:value-of
     89                                                        select="$leaf_value"/>                                         
     90                                                </xsl:otherwise>                                 
     91                                            </xsl:choose>
     92                                        </code>
     93                                    </xsl:when>
     94                                    <xsl:otherwise>                                   
     95                                        <xsl:variable
     96                                            name="leaf_value"
     97                                            select="format-number(self::element(), '#') cast as xs:string"
     98                                            as="xs:string"/>
     99                                        <xsl:variable
     100                                            name="is_URL"
     101                                            select="starts-with($leaf_value, 'http://') or starts-with($leaf_value, 'https://')"
     102                                            as="xs:boolean"/>
     103                                        <code class="leaf">
     104                                            <xsl:choose>
     105                                                <xsl:when
     106                                                    test="$is_URL">
     107                                                    <a href="{$leaf_value}"><xsl:value-of select="$leaf_value"/></a>
     108                                                </xsl:when>
     109                                                <xsl:otherwise>                                   
     110                                                    <xsl:value-of
     111                                                        select="$leaf_value"/>                                         
     112                                                </xsl:otherwise>                                 
     113                                            </xsl:choose>
     114                                        </code>                 
     115                                    </xsl:otherwise>                                 
     116                                </xsl:choose>
    60117                             </div>
    61118                         </xsl:when>
    62119                         <xsl:otherwise>
    63120                             <ul>
    64                                  <xsl:call-template name="Component_tree">
    65                                      <xsl:with-param name="nodeset" select="self::element()"/>
     121                                 <xsl:call-template
     122                                     name="Component_tree">
     123                                     <xsl:with-param
     124                                         name="nodeset"
     125                                         select="self::element()"/>
    66126                                 </xsl:call-template>
    67127                             </ul>
     
    75135    </xsl:template>
    76136
    77 
    78137    <xsl:template match="CMD">
     138        <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
     139            <meta charset="utf-8"/>
     140            <head>
     141                <title>CMDI collection "<xsl:value-of select="./Header/MdCollectionDisplayName" xmlns="cmd"/>"</title>
     142                <link rel="stylesheet" type="text/css" href="http://catalog.clarin.eu/ds/vlo/css/main.css"></link>
     143               
    79144                <style media="screen" type="text/css">
    80145                    <![CDATA[
     
    131196                    ]]>
    132197                </style>
     198            </head>
     199            <body>
    133200                <article style="background-color:#EEEEEE">
    134201                    <div class="endgame">
    135                         <p>
    136                             <h1>Resources</h1>
    137                             <table>
    138                                 <caption>Resources</caption>
    139                                 <thead>
    140                                     <tr>
    141                                         <th class="attribute">Reference to resource</th>
    142                                         <th class="attribute">Resource description</th>
    143                                         <th class="attribute">Resource MIME type</th>
    144                                         <th class="attribute">Resource Proxy ID</th>
    145                                     </tr>
    146                                 </thead>
    147                                 <tbody class="attributesTbody">
    148                                     <xsl:for-each select="Resources/ResourceProxyList/ResourceProxy">
    149                                         <xsl:variable name="URI"                                select="ResourceRef/text()"                                 as="xs:string"/>
    150                                         <tr>
    151                                             <td class="attributeValue">                                               
    152                                                 <xsl:variable name="protocol"                   select="fn:substring-before($URI, ':')"                     as="xs:string"/>
    153                                                 <xsl:choose>
    154                                                     <xsl:when test="$protocol = 'hdl'">
    155                                                         <xsl:variable name="HANDLE_PREFIX"      select="'http://hdl.handle.net'"                            as="xs:string"/>                                               
    156                                                         <xsl:variable name="Handle_reference"   select="fn:substring-after($URI, ':')"                      as="xs:string"/>
    157                                                         <xsl:variable name="Handle_HTTP_URL"    select="fn:concat($HANDLE_PREFIX, '/', $Handle_reference)"     as="xs:string"/>
    158                                                         <a href="{$Handle_HTTP_URL}"><xsl:value-of select="$Handle_HTTP_URL"/></a>
    159                                                     </xsl:when>
    160                                                     <xsl:otherwise>
    161                                                         <a href="{ResourceRef}"><xsl:value-of select="ResourceRef"/></a>
    162                                                     </xsl:otherwise>
    163                                                 </xsl:choose>                                               
    164                                             </td>
    165                                             <td class="attributeValue">
    166                                                 <xsl:value-of select="ResourceType"/>
    167                                             </td>
    168                                             <td class="attributeValue">
    169                                                 <xsl:value-of select="ResourceType/@mimetype"/>
    170                                             </td>
    171                                             <td class="attributeValue">
    172                                                 <xsl:value-of select="./@id"/>
    173                                             </td>
    174                                         </tr>
    175                                     </xsl:for-each>
    176                                 </tbody>
    177                             </table>
    178                         </p>
     202                        <xsl:if test="not(not(Resources/*[normalize-space()]))">
     203                            <p>                   
     204                                <h1>Resources</h1>
     205                                <table>
     206                                 <caption>Resources</caption>
     207                                 <thead>
     208                                     <tr>
     209                                         <th class="attribute">Reference to resource</th>
     210                                         <th class="attribute">Resource description</th>
     211                                         <th class="attribute">Resource MIME type</th>
     212                                         <th class="attribute">Resource Proxy ID</th>
     213                                     </tr>
     214                                 </thead>
     215                                 <tbody class="attributesTbody">
     216                                     <xsl:for-each
     217                                         select="Resources/ResourceProxyList/ResourceProxy">
     218                                         <xsl:variable
     219                                             name="URI"
     220                                             select="ResourceRef/text()"
     221                                             as="xs:string"/>
     222                                         <tr>
     223                                             <td class="attributeValue">                                               
     224                                                 <xsl:variable
     225                                                     name="protocol"
     226                                                     select="fn:substring-before($URI, ':')"
     227                                                     as="xs:string"/>
     228                                                 <xsl:choose>
     229                                                     <xsl:when
     230                                                         test="$protocol = 'hdl'">
     231                                                         <xsl:variable
     232                                                             name="HANDLE_PREFIX"
     233                                                             select="'http://hdl.handle.net'"
     234                                                             as="xs:string"/>                                               
     235                                                         <xsl:variable
     236                                                             name="Handle_reference"
     237                                                             select="fn:substring-after($URI, ':')"
     238                                                             as="xs:string"/>
     239                                                         <xsl:variable
     240                                                             name="Handle_HTTP_URL"
     241                                                             select="fn:concat($HANDLE_PREFIX, '/', $Handle_reference)"
     242                                                             as="xs:string"/>
     243                                                         <a href="{$Handle_HTTP_URL}">
     244                                                             <xsl:value-of
     245                                                                select="$Handle_HTTP_URL"/>
     246                                                         </a>
     247                                                     </xsl:when>
     248                                                     <xsl:otherwise>
     249                                                         <a href="{ResourceRef}">
     250                                                             <xsl:value-of
     251                                                                 select="ResourceRef"/>
     252                                                         </a>
     253                                                     </xsl:otherwise>
     254                                                 </xsl:choose>                                               
     255                                             </td>
     256                                             <td class="attributeValue">
     257                                                 <xsl:value-of select="ResourceType"/>
     258                                             </td>
     259                                             <td class="attributeValue">
     260                                                 <xsl:value-of select="ResourceType/@mimetype"/>
     261                                             </td>
     262                                             <td class="attributeValue">
     263                                                 <xsl:value-of select="./@id"/>
     264                                             </td>
     265                                         </tr>
     266                                     </xsl:for-each>
     267                                 </tbody>
     268                                </table>
     269                            </p>
     270                        </xsl:if>
    179271                    </div>
    180272                   
     
    184276                    </p>
    185277                </article>
     278            </body>
     279        </html>
    186280    </xsl:template>
    187281</xsl:stylesheet>
Note: See TracChangeset for help on using the changeset viewer.