[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

Re: [xsl] reversing or swapping nested node hierarchy


Subject: Re: [xsl] reversing or swapping nested node hierarchy
From: Chris Capon <abyss@xxxxxxxxxxx>
Date: Tue, 21 Mar 2006 11:24:36 -0500

Ok, I think I understand now.

Through the use of mode="" it is possible to reverse the order. 
Essentially, there are two templates that handle each node type, a mode=
version and a non-mode version.  The mode= version can process its nodes
in the opposite order of the non-mode version.


The example as provided works, but needs one minor change if the <a>,
<c> and <d> templates are to be called for those elements which do not
contain <b> elements.  The current template simply copies those nodes.

Change:

> <xsl:template match="@*|node()" mode="identity">
>   <xsl:copy>
>     <xsl:apply-templates select="@*|node()" mode="identity"/>
>   </xsl:copy>
> </xsl:template>

To:

<xsl:template match="@*|node()" mode="identity">
  <xsl:apply-templates select="." />
</xsl:template>

This allows the non-"mode" templates for <a>, <c> and <d> elements to be
invoked on nodes which are not handled by match="*[b]".


It occurs to me that the order in which these templates are evaluated is
significant.  For instance, match="*" and match="*[b]" could both apply
to an element containing a <b> element.

Is it valid to design a stylesheet which depends on the order in which
templates are declared?

Thanks very much for you help in solving this problem.
Chris.


Current Thread