[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: How to Reorder Items & Number Them Sequentially?

Subject: Re: How to Reorder Items & Number Them Sequentially?
From: Jeni Tennison <Jeni.Tennison@xxxxxxxxxxxxxxxx>
Date: Mon, 22 May 2000 13:39:28 +0100
reorder items html

>What I'd like to know is:  how I can create this ordering of the
>output and retain the ability to number the items sequentially using
>XSLT?  I have figured out a way to reorder the elements by using
>nested for-each loops, but there appears to be no way to get
>sequential numbering when I do it that way.  I'm sure there must be
>a functional approach that makes this easy.

Here are a couple of templates that give you the ordering, grouping and
numbering that you want.  They are not pretty.  It works by identifying,
from the current node, which node should be next in the output list, and
then operating on that.  Let me know if you need it explained further.

<xsl:key name="animalTypes" match="animal" use="@type" />

<xsl:template match="animals">
  Here are my pets:
  <xsl:apply-templates select="animal[1]">
    <xsl:with-param name="number">1</xsl:with-param>

<xsl:template match="animal">
  <xsl:param name="number" />
  <xsl:variable name="type" select="@type" />
  <xsl:value-of select="$number" />. <xsl:value-of select="@type" />
(<xsl:value-of select="@name" />)
    <!-- this isn't the last of this type in the document -->
    <xsl:when test="generate-id(.) != generate-id(key('animalTypes',
      <xsl:apply-templates select="following-sibling::animal[@type =
        <xsl:with-param name="number" select="$number + 1" />
    <!-- move onto the next in order -->
      <xsl:apply-templates select="key('animalTypes',
$type)[1]/following-sibling::animal[generate-id(.) =
generate-id(key('animalTypes', @type)[1])][1]">
        <xsl:with-param name="number" select="$number + 1" />

I hope that helps.



Dr Jeni Tennison
Epistemics Ltd, Strelley Hall, Nottingham, NG8 6PE
Telephone 0115 9061301 ? Fax 0115 9061304 ? Email

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list

Current Thread


Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
First Name
Last Name
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.