Subject: Re: [xsl] sequence numbering. From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx> Date: Wed, 27 Mar 2002 13:43:15 +0000 |
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
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
RE: [xsl] problem with xsl:number, Michael Kay | Thread | Re: Re: [xsl] sequence numbering., william locksman |
RE: [xsl] Fixing &lt;b&gt;, tammy | Date | RE: [xsl] html2xml?, naha |
Month |