Subject: Re: [xsl] Grouping and Numbering From: Wendell Piez <wapiez@xxxxxxxxxxxxxxxx> Date: Fri, 25 May 2007 19:16:30 -0400 |
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:key name="g" match="group_id" use="." />
<xsl:output indent="yes"/>
<xsl:variable name="g" select="/sample/result/details/group_id[generate-id()=generate-id(key('g',.))]"/>
<xsl:template match="sample"> <xsl:for-each select="$g">
<xsl:sort select="."/>
<xsl:variable name="p" select="position()-1"/>
<xsl:variable name="c" select="count(key('g',$g[.<current()]))"/>
<xsl:for-each select="key('g',.)">
<output row="{$c+$p+position()}"><xsl:value-of select="."/></output>
We write an 'output' element. The value of its @row is calculated as: * The count of all the members of the groups preceding this one (since they'll appear above this one) * The number of blank lines we'll also include, which happens to be $p * The position of this member of the group within the group
</xsl:for-each>
<xsl:if test="position()!=last()">
<output row="{$c+count(key('g',.))+$p+1}"/>
</xsl:if> </xsl:for-each> </xsl:template>
Cheers, Wendell
====================================================================== Wendell Piez mailto:wapiez@xxxxxxxxxxxxxxxx Mulberry Technologies, Inc. http://www.mulberrytech.com 17 West Jefferson Street Direct Phone: 301/315-9635 Suite 207 Phone: 301/315-9631 Rockville, MD 20850 Fax: 301/315-8285 ---------------------------------------------------------------------- Mulberry Technologies: A Consultancy Specializing in SGML and XML ======================================================================
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] Grouping and Numbering, David Carlisle | Thread | Re: [xsl] Grouping and Numbering, Mukul Gandhi |
Re: [xsl] XPath MOD 10 calculation, David Carlisle | Date | Re: [xsl] Grouping and Numbering, Mukul Gandhi |
Month |