Node:Step 5, Next:Step 6, Previous:Step 4, Up:Tutorial
The root elements in annotations is ordered according to the
lexicographical order of the file or directory names. If we want to
process them in a specific order, one approach could be to name the
files and directories following some naming scheme. However, this
usually leads to ugly names (such as 01mercury,
02venus, 03earth,
04mars). It is also difficult to maintain (for
example adding asteroid-belt between earth and
mars might need the existing files to be renamed. The sorting may also
depend on the locale.
The most reliable way of ensuring a certain order is to perform the sorting inside the XSLT script. Data representing the sorting criteria may need to be added to the source files.
In this tutorial, the status attribute in the
source files will be used as the sorting value. This will be a number
that indicates the file's relative order amongst its siblings. We add
a xsl:sort element to the loop to ensure that the
children appear in the correct order.
<div class="nav-sub">
<xsl:if test="/article/TBA:children/article">
<xsl:for-each select="/article/TBA:children/article">
<xsl:sort select="@status" data-type="number"
order="ascending"/>
<li>
...
Instead of writing the select value as
/article/TBA:children/article, you might want to
write it as /*/TBA:children/* - this way, it will
work independently of the XML vocabulary of the source files, making it
easier to reuse this XSLT code.
This step can be tested by running Transbuild on the build
script file tb-step05.xml. In the nest step, some
of the other annotations will be used.