Changeset 20150


Ignore:
Timestamp:
2009-08-05T13:29:20+12:00 (15 years ago)
Author:
kjdon
Message:

indented file nicely

File:
1 edited

Legend:

Unmodified
Added
Removed
  • greenstone3/trunk/web/ui/xslt/preProcess.xsl

    r19917 r20150  
    22
    33<xsl:stylesheet version="1.0"
    4 xmlns:gsf="http://www.greenstone.org/greenstone3/schema/ConfigFormat"
    5 xmlns:gslib="http://www.greenstone.org/skinning"
    6 xmlns:java="http://xml.apache.org/xslt/java"
    7 xmlns:util="xalan://org.greenstone.gsdl3.util.XSLTUtil"
    8 xmlns:xalan="http://xml.apache.org/xalan"
    9 xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    10 xmlns:xslt="output.xsl"
    11 xmlns:gs3="http://www.greenstone.org/gs3"
    12 >
     4  xmlns:gsf="http://www.greenstone.org/greenstone3/schema/ConfigFormat"
     5  xmlns:gslib="http://www.greenstone.org/skinning"
     6  xmlns:java="http://xml.apache.org/xslt/java"
     7  xmlns:util="xalan://org.greenstone.gsdl3.util.XSLTUtil"
     8  xmlns:xalan="http://xml.apache.org/xalan"
     9  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
     10  xmlns:xslt="output.xsl"
     11  xmlns:gs3="http://www.greenstone.org/gs3"
     12  >
    1313
    14 <xsl:output method="xml"/>
     14  <xsl:output method="xml"/>
     15
     16  <xsl:template match="/">
     17
     18    <xsl:for-each select="/skinAndLibraryXsl/skinXsl/xsl:stylesheet">
     19     
     20      <!-- produce an exact copy of skin stylesheet, with gslib nodes expanded. -->
     21      <xsl:variable name="element-name" select="name()"/>
     22      <xsl:element name="{$element-name}">
     23    <xsl:for-each select="@*">
     24      <xsl:variable name="attribute-name" select="name()"/>
     25      <xsl:attribute name="{$attribute-name}">
     26        <xsl:value-of select="."/>
     27      </xsl:attribute>
     28    </xsl:for-each>
     29   
     30    <!-- merge the attributes of the library stylesheet -->
     31    <xsl:for-each select="/skinAndLibraryXsl/libraryXsl/xsl:stylesheet/@*">
     32      <xsl:variable name="attribute-name" select="name()"/>
     33      <xsl:attribute name="{$attribute-name}">
     34        <xsl:value-of select="."/>
     35      </xsl:attribute>
     36    </xsl:for-each>
     37   
     38    <xsl:call-template name="expand_gslib_elements" />
     39   
     40    <!-- add content of library to the skin stylesheet -->
     41    <xsl:for-each select="/skinAndLibraryXsl/libraryXsl/xsl:stylesheet">
     42      <xsl:call-template name="expand_gslib_elements" />
     43    </xsl:for-each>
     44   
     45
     46      </xsl:element>
     47     
     48     
     49    </xsl:for-each>
     50  </xsl:template>
    1551
    1652
     53  <!-- produce an exact copy of the current node, but expand and replace all elements belonging to the gslib namespace. -->
     54  <xsl:template name="expand_gslib_elements">
    1755
    1856
    19 <xsl:template match="/">
    20 
    21 
    22 
    23 
    24     <xsl:for-each select="/skinAndLibraryXsl/skinXsl/xsl:stylesheet">
    25    
    26         <!-- produce an exact copy of skin stylesheet, with gslib nodes expanded. -->
    27         <xsl:variable name="element-name" select="name()"/>
    28         <xsl:element name="{$element-name}">
    29             <xsl:for-each select="@*">
    30                 <xsl:variable name="attribute-name" select="name()"/>
    31                 <xsl:attribute name="{$attribute-name}">
    32                     <xsl:value-of select="."/>
    33                 </xsl:attribute>
    34             </xsl:for-each>
    35        
    36             <!-- merge the attributes of the library stylesheet -->
    37             <xsl:for-each select="/skinAndLibraryXsl/libraryXsl/xsl:stylesheet/@*">
    38                 <xsl:variable name="attribute-name" select="name()"/>
    39                 <xsl:attribute name="{$attribute-name}">
    40                     <xsl:value-of select="."/>
    41                 </xsl:attribute>
    42             </xsl:for-each>
    43            
    44              <xsl:call-template name="expand_gslib_elements" />
    45              
    46              <!-- add content of library to the skin stylesheet -->
    47              <xsl:for-each select="/skinAndLibraryXsl/libraryXsl/xsl:stylesheet">
    48                 <xsl:call-template name="expand_gslib_elements" />
    49              </xsl:for-each>
    50              
    51 
    52         </xsl:element>
    53      
    54        
    55     </xsl:for-each>
    56 </xsl:template>
    57 
    58 
    59 <!-- produce an exact copy of the current node, but expand and replace all elements belonging to the gslib namespace. -->
    60 <xsl:template name="expand_gslib_elements">
    61 
    62 
    63  <xsl:for-each select="*|text()">
    64   <xsl:choose>
    65  
    66    
    67     <!-- if node has gslib prefix, expand it into appropriate copy-of or call-template element -->
    68     <xsl:when test="namespace-uri(.)=namespace::gslib">
    69    
    70         <xsl:variable name="name" select="local-name()"/>
    71         <xsl:choose>
    72        
    73         <!-- if library contains a variable of this name, expand to it's value -->
    74         <xsl:when test="/skinAndLibraryXsl/libraryXsl//xsl:variable[@name = $name]">
    75             <xsl:element name="xsl:copy-of">
    76                 <xsl:attribute name="select">$<xsl:value-of select="local-name()" /></xsl:attribute>
    77             </xsl:element>
    78         </xsl:when>
    79        
    80        
    81         <!-- if library contains a template of this name, expand to a call-template and pass attributes as parameters -->
    82         <xsl:otherwise>
    83             <xsl:element name="xsl:call-template">
    84                 <xsl:attribute name="name"> <xsl:value-of select="local-name()" /></xsl:attribute>
    85                
    86                 <xsl:for-each select="@*">
    87                     <xsl:element name="xsl:with-param">
    88                         <xsl:attribute name="name"><xsl:value-of select="name()"/></xsl:attribute>
    89                         <xsl:call-template name="convert_attVal_to_valueOf" />
    90                     </xsl:element>                 
    91                 </xsl:for-each>
    92             </xsl:element>
    93         </xsl:otherwise>
    94    
    95         </xsl:choose>   
    96     </xsl:when>
    97 
    98     <xsl:when test="self::text()">
    99      <xsl:value-of select="."/>
    100     </xsl:when>
    101 
    102         <!-- if a regular node v2 -->
    103     <xsl:otherwise>
    104      <xsl:variable name="element-name" select="name()"/>
    105      <xsl:variable name="element-namespace" select="namespace-uri()"/>
    106      <xsl:element name="{$element-name}" namespace="{$element-namespace}">
    107       <xsl:for-each select="@*">
    108        <xsl:variable name="attribute-name" select="name()"/>
    109        <xsl:attribute name="{$attribute-name}">
    110         <xsl:value-of select="."/>
    111        </xsl:attribute>
    112       </xsl:for-each>
    113       <xsl:call-template name="expand_gslib_elements" />
    114      </xsl:element>
    115     </xsl:otherwise>
     57    <xsl:for-each select="*|text()">
     58      <xsl:choose>
    11659   
    11760   
    118   </xsl:choose>
    119  </xsl:for-each>
     61    <!-- if node has gslib prefix, expand it into appropriate copy-of or call-template element -->
     62    <xsl:when test="namespace-uri(.)=namespace::gslib">
     63     
     64      <xsl:variable name="name" select="local-name()"/>
     65      <xsl:choose>
     66       
     67        <!-- if library contains a variable of this name, expand to it's value -->
     68        <xsl:when test="/skinAndLibraryXsl/libraryXsl//xsl:variable[@name = $name]">
     69          <xsl:element name="xsl:copy-of">
     70        <xsl:attribute name="select">$<xsl:value-of select="local-name()" /></xsl:attribute>
     71          </xsl:element>
     72        </xsl:when>
     73       
     74       
     75        <!-- if library contains a template of this name, expand to a call-template and pass attributes as parameters -->
     76        <xsl:otherwise>
     77          <xsl:element name="xsl:call-template">
     78        <xsl:attribute name="name"> <xsl:value-of select="local-name()" /></xsl:attribute>
     79       
     80        <xsl:for-each select="@*">
     81          <xsl:element name="xsl:with-param">
     82            <xsl:attribute name="name"><xsl:value-of select="name()"/></xsl:attribute>
     83            <xsl:call-template name="convert_attVal_to_valueOf" />
     84          </xsl:element>                   
     85        </xsl:for-each>
     86          </xsl:element>
     87        </xsl:otherwise>
     88       
     89      </xsl:choose>
     90    </xsl:when>
    12091
    121 </xsl:template>
     92    <xsl:when test="self::text()">
     93      <xsl:value-of select="."/>
     94    </xsl:when>
    12295
    123 <!-- converts an attribute value (the current node) into either a literal value or an <xsl:value-of> element -->
    124 <xsl:template name="convert_attVal_to_valueOf">
    125 
    126     <xsl:choose>
    127     <!-- if attribute is not literal (starts with a "{") -->
    128         <xsl:when test="starts-with(string(), '&#123;')">
    129             <xsl:element name="xsl:value-of">
    130                 <xsl:attribute name="disable-output-escaping">yes</xsl:attribute>
    131                 <xsl:attribute name="select"><xsl:value-of select="substring(string(),2,string-length()-2)"/></xsl:attribute>
    132                 </xsl:element>
    133         </xsl:when>
    134         <xsl:otherwise>
    135             <xsl:value-of select="."/>
    136         </xsl:otherwise>
    137     </xsl:choose>
    138 </xsl:template>
    139 
    140 <xsl:template name="create_dummy_variables">
    141     <xsl:for-each select="//*[namespace-uri()=namespace::gslib]">
    142         <xsl:element name="xsl:variable">
    143             <xsl:attribute name="name">
    144                 <xsl:value-of select="local-name()"/>
    145             </xsl:attribute>
    146         </xsl:element> 
    147     </xsl:for-each>
    148 </xsl:template>
     96    <!-- if a regular node v2 -->
     97    <xsl:otherwise>
     98      <xsl:variable name="element-name" select="name()"/>
     99      <xsl:variable name="element-namespace" select="namespace-uri()"/>
     100      <xsl:element name="{$element-name}" namespace="{$element-namespace}">
     101        <xsl:for-each select="@*">
     102          <xsl:variable name="attribute-name" select="name()"/>
     103          <xsl:attribute name="{$attribute-name}">
     104        <xsl:value-of select="."/>
     105          </xsl:attribute>
     106        </xsl:for-each>
     107        <xsl:call-template name="expand_gslib_elements" />
     108      </xsl:element>
     109    </xsl:otherwise>
    149110   
    150111   
     112      </xsl:choose>
     113    </xsl:for-each>
     114
     115  </xsl:template>
     116
     117  <!-- converts an attribute value (the current node) into either a literal value or an <xsl:value-of> element -->
     118  <xsl:template name="convert_attVal_to_valueOf">
     119
     120    <xsl:choose>
     121      <!-- if attribute is not literal (starts with a "{") -->
     122      <xsl:when test="starts-with(string(), '&#123;')">
     123    <xsl:element name="xsl:value-of">
     124      <xsl:attribute name="disable-output-escaping">yes</xsl:attribute>
     125      <xsl:attribute name="select"><xsl:value-of select="substring(string(),2,string-length()-2)"/></xsl:attribute>
     126    </xsl:element>
     127      </xsl:when>
     128      <xsl:otherwise>
     129    <xsl:value-of select="."/>
     130      </xsl:otherwise>
     131    </xsl:choose>
     132  </xsl:template>
     133
     134  <xsl:template name="create_dummy_variables">
     135    <xsl:for-each select="//*[namespace-uri()=namespace::gslib]">
     136      <xsl:element name="xsl:variable">
     137    <xsl:attribute name="name">
     138      <xsl:value-of select="local-name()"/>
     139    </xsl:attribute>
     140      </xsl:element>   
     141    </xsl:for-each>
     142  </xsl:template>
     143 
     144 
    151145</xsl:stylesheet>
Note: See TracChangeset for help on using the changeset viewer.