|
[XSL-LIST Mailing List Archive Home]
[By Thread]
[By Date]
[Recent Entries]
[Reply To This Message]
Re: Re: sequence numbering.
Subject: Re: Re: sequence numbering.
From: "william locksman" <vsd18@xxxxxxxxxxxxxx>
Date: 27 Mar 2002 17:24:45 -0000
|
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

|
PURCHASE STYLUS STUDIO ONLINE TODAY!
Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!
Download The World's Best XML IDE!
Accelerate XML development with our award-winning XML IDE - Download a free trial today!
Subscribe in XML format
| RSS 2.0 |
|
| Atom 0.3 |
|
|