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

Creating sequences using "to" operator

Numeric sequences can be conveniently created using "to" operator. The operator creates a sequence of numbers starting from the number before the operator and ending with the number after the operator. If the first number is larger than the second one empty sequence is outputed.
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="1 to 5"/>
                  </xxx>
                  <yyy>
                        <xsl:value-of  select="-3 to 3"/>
                  </yyy>
                  <zzz>
                        <xsl:value-of  select="3 to 3"/>
                  </zzz>
                  <rrr>
                        <xsl:value-of  select="5 to 2"/>
                  </rrr>
            </xsl:template>

      </xsl:stylesheet>
XML

      <aaa/>
Output

      <xxx>1 2 3 4 5</xxx>
      <yyy>-3 -2 -1 0 1 2 3</yyy>
      <zzz>3</zzz>
      <rrr/>


Previous chapter: Templates - basic usage
Next chapter: Sequence Combinations
Previous page: Copying sequences
Next page: Combination of sequences created with "to" operator