XslWebMaker Advanced - Subdirectory Handling

Page Updated: Mon, 23 Sep 2019 23:40 AEST (UTC+1000)

In your source directory you may want to organise your web site by including subdirectories. Pages within your subdirectories well need special handling. For example, when these pages reference a common navigation menu system, the links within that menu will be slightly different.

  1. In your source .html files that are within source subdirectories add <xwm:subDirectoryFlag />
      ...
      <xwm:commonHead />
      <xwm:subDirectoryFlag />
      <xwm:directoryDependantHead />        
    </head>
    <body>
      <xwm:navigation />
      ...
     
  2. In your xwmToXhtml.xslt define a variable, here directoryLevel, that returns a string "../" if the <xwm:subDirectoryFlag /> element is in your source .html files.

    Wherever you need to have different urls depending on whether the page is in a subdirectroy or not, reference the directoryLevel variable.

    
    <xsl:variable name="directoryLevel" xml:space="no">
      <xsl:choose>
        <xsl:when test="//*[local-name()='subDirectoryFlag']">../</xsl:when>
        <xsl:otherwise></xsl:otherwise>
      </xsl:choose>
    </xsl:variable>
      
    <!-- Needed to allow the subDirectoryFlag in the source doc -->
    <xsl:template match="*[local-name()='subDirectoryFlag']" xml:space="preserve">
    </xsl:template>
    ...
    <xsl:template match="*[local-name()='directoryDependantHead']" xml:space="preserve">
      <xsl:comment> directoryDependantHead start </xsl:comment>
      <link type="text/css" rel="stylesheet" href="{concat($directoryLevel, 'minimalist.css')}" />
      <script type="text/javascript" src="{concat($directoryLevel, 'webDateTime.js')}"></script>  
      <xsl:comment> directoryDependantHead Finish </xsl:comment>
    </xsl:template>  
    ...
    <xsl:template match="*[local-name()='navigation']" xml:space="preserve">
      <div id="navigation">
        <ul>
          <li><a href="{concat($directoryLevel, 'index.html')}">Home</a></li> 
          <li>Calendar
            <ul>
              <li><a href="{concat($directoryLevel, 'pastCalendar.html')}">Past</a></li>
            </ul>
          </li>
          <li><a href="{concat($directoryLevel, 'contact.html')}">Contact</a></li> 
        </ul>           
      </div>
    </xsl:template>