previous  next

Full Axis Stylesheet

This is implemented as a classic “modified identity transformation”.

<xsl:import href="xq2xq.xsl"/>
.
.
.
<xsl:template match="StepExpr[ReverseAxis/data='preceding']">
(let $here := . return
   reverse(root()/descendant::
<xsl:apply-templates select="NodeTest"/>
[. << $here][not(descendant::node()[. is $here])]))
<xsl:apply-templates select="* except (ReverseAxis|NodeTest)"/>
</xsl:template>

This template produces an expression that returns nodes in reverse document order. A higher priority template matches steps that are not part of a larger Path expression and applies the reverse() function when required.