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

[xsl] Reverse axis, reverse document order, xsl:for-each


Subject: [xsl] Reverse axis, reverse document order, xsl:for-each
From: Michael Ludwig <mlu@xxxxxxxxxxxxx>
Date: Thu, 28 Feb 2008 10:28:23 +0100

I want to process nodes collected on a reverse axis in reverse document
order (RDO). Using xsl:for-each, it doesn't work. Why is this so? Why
does xsl:for-each obliterate the direction offered by the axis? Why does
it revert reversion?

What precise situation does RDO apply to? Is it only for node test
immediately attached to the axis step?

And, last question, is there a way to have a pointer (xsl:variable) to
nodes in RDO without resorting to copying or reconstructing? (See
example two in the stylesheet below.)

I'm using XSL language version 1.0 with libxslt.

mludwig@forelle:~/xpg/Werkstatt/xsl-rdo > expand -t1 rdo.xml
<Urmel>
 <elm>eins</elm>
 <elm>zwei</elm>
 <elm>drei</elm>
</Urmel>

mludwig@forelle:~/xpg/Werkstatt/xsl-rdo > expand -t1 rdo.xsl
<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
 xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
 <xsl:output method="text"/>
 <xsl:template match="/">
  <xsl:variable name="my-node" select=".//elm[ . = 'drei' ]"/>
  <!-- one -->
  <xsl:for-each select="$my-node/preceding-sibling::elm">
   <xsl:value-of select="concat(. , '&#10;')"/>
  </xsl:for-each>
  <!-- two, same thing using a variable -->
  <xsl:variable name="prec" select="$my-node/preceding-sibling::elm"/>
  <xsl:for-each select="$prec">
   <xsl:value-of select="concat(. , '&#10;')"/>
  </xsl:for-each>
 </xsl:template>
</xsl:stylesheet>

mludwig@forelle:~/xpg/Werkstatt/xsl-rdo > xsltproc rdo.xsl rdo.xml
eins
zwei
eins
zwei

The output I want and expect is the reverse:
zwei
eins
zwei
eins

Michael


Current Thread
Keywords
xsl