Node:Step 7, Next:, Previous:Step 6, Up:Tutorial



Step 7: More sophistication through XSLT

You've now seen the main features of Transbuild: the processing model to generate the target tree, the file renaming mechanism, the annotations and how to make use of them.

In this step, we will enhance the XSLT script to detect if the current page is a section page and disable that link in the section navigation bar. This is done by comparing the TBA:source attribute of the annotation file to that of the current file. When they are different a link is generated, when they are the same a link is not generated.

<xsl:template match="article">
  <body>
    <div class="nav-top">
      <ul>
        <li><a href="{TBF:href('/index.xml')}">Home</a></li>

        <xsl:for-each select="/article/TBA:dir/TBA:children/article">
          <xsl:sort select="@status" data-type="number"
                    order="ascending"/>
          <li>

            <xsl:choose>
              <xsl:when test="@TBA:source = /*/@TBA:source">
                <span class="current">
                  <xsl:value-of select="title"/>
                </span>
              </xsl:when>

              <xsl:otherwise>
                <a href="{TBF:href(@TBA:source)}">
                  <xsl:value-of select="title"/>
                </a>
              </xsl:otherwise>
            </xsl:choose>

          </li>
        </xsl:for-each>
      </ul>
    </div>
    ...

We'll also hide the `bread-crumb' navigation link on the home page. The non-breaking space is needed so the spacing for the `bread-crumbs' navigation appears even though there are no links in it.

...
<div class="nav-hier">
  <xsl:if test="/*/@TBA:source != /*/TBA:ancestors/*[1]/@TBA:source">
    <xsl:for-each select="/article/TBA:ancestors/article">
      <xsl:if test="position() != 1">
        <xsl:text> &gt; </xsl:text>
      </xsl:if>
      <a href="{TBF:href(@TBA:source)}">
        <xsl:value-of select="title"/>
      </a>
    </xsl:for-each>
  </xsl:if>
  <xsl:text disable-output-escaping="yes">&amp;nbsp;</xsl:text>
</div>
...

This step can be tested with the tb-step07.xml build script.

A large part of the power of Transbuild comes from the inherent power and flexibility of XSLT: become an expert in using XSLT and you'll become an expert in using Transbuild!