Previous | Next | Indexes
Zvon > Tutorials > XSLT 2.0 Tutorial > Sequences (7/10) >

Function reverse

The reverse() function reverses the order in the sequence. Note the brackets in the second example. The reverse() function accepts precisely one argument. As the arguments of functions are separated by comma, an argument which creates a sequence must be enclosed by brackets.
XSLT

      <xsl:stylesheet
                  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                  version="2.0">
            <xsl:output  method="xml"
                        indent="yes"
                        omit-xml-declaration="yes"/>

            <xsl:template  match="/aaa">
                  <xxx>
                        <xsl:value-of  select="reverse(1 to 5)"/>
                  </xxx>
                  <yyy>
                        <xsl:value-of  select="reverse(('c','b','a'))"/>
                  </yyy>
                  <zzz>
                        <xsl:value-of  select="reverse(bbb)"/>
                  </zzz>
            </xsl:template>

      </xsl:stylesheet>
XML

      <aaa>
            <bbb>b1</bbb>
            <bbb>b2</bbb>
            <bbb>b3</bbb>
      </aaa>
Output

      <xxx>5 4 3 2 1</xxx>
      <yyy>a b c</yyy>
      <zzz>b3 b2 b1</zzz>


Previous chapter: Templates - basic usage
Next chapter: Sequence Combinations
Previous page: Combination of sequences created with "to" operator
Next page: Creation of sequences using for ... in ... return instruction