Changeset 34300

Show
Ignore:
Timestamp:
28.07.2020 17:18:44 (7 days ago)
Author:
ak19
Message:

XSLT to generate columns for GS3 groups now working for wmtb model interface, while still preserving the old way if we ever want to go back or reuse either method for Jenny's customisations tutorials.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • main/trunk/model-interfaces-dev/wmtb/transform/pages/home.xsl

    r34277 r34300  
    6464                <tbody class="wsite-multicol-tbody"> 
    6565                  <tr class="wsite-multicol-tr"> 
    66                 <xsl:call-template name="collectionAndGroupLinks"/> 
     66                <!-- <xsl:call-template name="collectionAndGroupLinks"/> --> 
     67 
     68                <!-- output the groups, the following outputs them column wise --> 
     69                <xsl:apply-templates select="groupList/group" mode="displayGroupInfo" /> 
     70                <!-- then output the collectionList in a final column --> 
     71                <xsl:apply-templates select="collectionList/collection" mode="displayCollInfo" /> 
    6772                  </tr> 
     73                   
    6874                </tbody> 
    6975              </table> 
     
    8894     
    8995    <xsl:template name="collectionsList"> 
    90         <!-- for every collection in the library --> 
     96        <!-- for every collection in the library --> 
    9197        <xsl:for-each select="./collectionList/collection">      
    9298            <xsl:call-template name="collDescription"/>              
    9399        </xsl:for-each> 
    94100    </xsl:template> 
    95  
    96     <xsl:template name="collDescription"> 
     101     
     102    <!-- 
     103        Template has match and name attributes allowing this to be called with both 
     104        apply-templates and call-template. 
     105        https://stackoverflow.com/questions/6478163/can-an-xslt-template-carry-both-name-and-match-attributes 
     106    --> 
     107    <xsl:template match="collection" name="collDescription" mode="displayColl"> 
    97108      <xsl:variable name="collectionFolder" select="@name"/> 
    98109      <xsl:variable name="collectionName" select="displayItemList/displayItem[@name='name']"/> 
     
    136147        <td class="wsite-multicol-col" style="width:33.333333333333%; padding:0 15px;"> 
    137148          <xsl:if test="name() = 'collection'"> 
    138           <xsl:call-template name="collDescription"/> 
    139         </xsl:if> 
    140         <xsl:if test="name() = 'group'"> 
    141           <xsl:call-template name="customGroupDescription"/> 
    142         </xsl:if> 
     149        <xsl:call-template name="collDescription"/> 
     150          </xsl:if> 
     151          <xsl:if test="name() = 'group'">         
     152        <xsl:call-template name="customGroupDescription"/> 
     153          </xsl:if> 
    143154        </td> 
    144155          </xsl:for-each> 
    145        
    146     </xsl:template> 
     156    </xsl:template> 
     157     
     158    <!-- https://stackoverflow.com/questions/93511/counter-inside-xslfor-each-loop 
     159    will not work, since we have an if-statement inside the for loop to filter for groups. 
     160    Instead, counting only the groups using Borodin's solution (still xslt 1.0) from 
     161    https://stackoverflow.com/questions/16504727/increment-counter-in-xslt-1-0 works. 
     162 
     163    While that gives us a proper counter not dependent on position(), it doesn't solve 
     164    that we need to open a tag (td) on odd count and close it on even. 
     165    For that, the solution is at: 
     166    https://stackoverflow.com/questions/17992481/xsl-wrap-every-2-items-in-the-for-each-with-a-div 
     167 
     168    General: https://stackoverflow.com/questions/4478045/what-are-the-differences-between-call-template-and-apply-templates-in-xsl 
     169    --> 
     170    <xsl:template match="group" mode="displayGroupInfo"> 
     171      <xsl:variable name="counter"><xsl:value-of select="1+count(preceding-sibling::group)])"/></xsl:variable> 
     172      <xsl:if test="($counter mod 2) = 1"> 
     173        <td class="wsite-multicol-col" style="width:33.333333333333%; padding:0 15px;"> 
     174          <xsl:apply-templates select=". |  following-sibling::group[1]" /> 
     175          <!-- calls the template match="group" without mode this time --> 
     176        </td> 
     177      </xsl:if> 
     178    </xsl:template> 
     179 
     180    <!-- We want collections to appear in a separate and single column. 
     181         So we don't do even odd columns here. --> 
     182    <xsl:template match="collection" mode="displayCollInfo"> 
     183      <!--<xsl:variable name="counter"><xsl:value-of select="1+count(preceding-sibling::collection)])"/></xsl:variable> 
     184      <xsl:if test="($counter mod 2) = 1">--> 
     185        <td class="wsite-multicol-col" style="width:33.333333333333%; padding:0 15px;"> 
     186          <!--<xsl:apply-templates select=". |  following-sibling::collection[1]" />--> 
     187          <xsl:apply-templates select="." mode="displayColl"/> 
     188              <!-- why does calling the template match="collection" without some mode 
     189               attr this time NOT work? --> 
     190        </td> 
     191      <!--</xsl:if>--> 
     192    </xsl:template>  
     193 
    147194    <xsl:template match="/page/xsltparams"> 
    148195      <!-- suppress xsltparam block in page --> 
     
    150197 
    151198    <!-- Modified version of <gslib:groupLinkWithImage/>--> 
    152     <xsl:template name="customGroupDescription"> 
     199    <!--  
     200         Template has match and name attributes allowing this to be called with both 
     201         apply-templates and call-template. 
     202         https://stackoverflow.com/questions/6478163/can-an-xslt-template-carry-both-name-and-match-attributes 
     203    --> 
     204    <xsl:template match="group" name="customGroupDescription"> 
     205 
    153206      <xsl:variable name="short"><xsl:value-of select="shortDescription"/></xsl:variable> 
    154207      <xsl:variable name="desc"><xsl:value-of select="description"/></xsl:variable>