This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: Re: sequence numbering.
- From: "william locksman" <vsd18 at rediffmail dot com>
- To: xsl-list at lists dot mulberrytech dot com
- Date: 27 Mar 2002 17:24:45 -0000
- Subject: Re: Re: [xsl] sequence numbering.
- Reply-to: xsl-list at lists dot mulberrytech dot com
Hi Jenni
Your reply was really a great learning .
about the name space,
The Declartion i am using is
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xalan="http://xml.apache.org/xslt"
xmlns:redirect="org.apache.xalan.xslt.extensions.Redirect"extension-element-prefixes="redirect"
version="1.0">
and i am using XALAN processor
On Wed, 27 Mar 2002 Jeni Tennison wrote :
>Hi William,
>
> > Hi the solution Michael Suggested seems to fit my purpose, But
>Since
> > i am a newbie to XSL , I do not know how to form a temporary
>tree
> > that contains sorted sequence.
>
>You can create a temporary tree by creating it within an
>xsl:variable:
>
> <xsl:variable name="temporary-tree">
> <xsl:for-each select="product">
> <xsl:sort select="color" />
> <xsl:copy-of select="." />
> </xsl:for-each>
> </xsl:variable>
>
>This assigns to the $temporary-tree variable a result tree
>fragment
>that contains a number of product elements, copies of the ones in
>your
>original document, sorted in order of their color.
>
>You can then convert the temporary tree into a node set using a
>node-set extension function, for example exsl:node-set():
>
> exsl:node-set($temporary-tree)
>
>Which extension function you use depends on what your processor
>supports. Most processors support a node-set() extension function
>of
>some form or another; check your processor's documentation to
>find out
>what namespace you need to declare for it. If you have problems
>with
>this, let us know, telling us which processor you're using.
>
>When you've converted the result tree fragment (the temporary
>tree) to
>a node set, you can operate over it in exactly the same way as
>you
>normally do, and number them with judicious use of the count
>attribute
>as Mike suggested:
>
> <xsl:for-each
>select="exsl:node-set($temporary-tree)/product">
> <xsl:variable name="this_color" select="color" />
> <xsl:number count="product[color = $this_color]" />
> ...
> </xsl:for-each>
>
>What you're actually doing here is grouping the products
>together
>based on their colour and then numbering them based on their
>position
>within that group. If you find that the process described above
>goes
>too slowly, you could use a grouping method instead. To give you
>an
>idea of the process, the XSLT 2.0 grouping method would be:
>
> <xsl:for-each-group select="product" group-by="color">
> <xsl:sort select="color" />
> <xsl:for-each select="current-group()">
> <xsl:number value="position()" />
> ...
> </xsl:for-each>
> </xsl:for-each-group>
>
>If you decide that you want to use this method, then have a read
>of
>http://www.jenitennison.com/xslt/grouping/muenchian.html for a
>description of how to do the grouping in XSLT 1.0.
>
>Cheers,
>
>Jeni
>
>---
>Jeni Tennison
>http://www.jenitennison.com/
>
>
> XSL-List info and archive:
>http://www.mulberrytech.com/xsl/xsl-list
>
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list