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

Re:how to group equal nodes by a it's position()

Subject: Re:how to group equal nodes by a it's position()
From: "Yang" <sfyang@xxxxxxxxxxxxx>
Date: Sun, 30 Sep 2001 11:40:20 +0800
select size 1 name
Hi,   Dmitri,

Basically your problem is of typical group by position.  You can
the solutions for this type of problem from jeni site, dpawson site,
vbxml snipper center..

However,  since you request is to allow various number of elements
for each group,  then an additional param has to be considered.

The following generic  xslt is allow you assign number of elemens
and number of row for each group table.   To be more flexible to input the
required elements
and row number, a set of line element are adding to the xml doc(see xml
below) .

 The core code to do the grouping with given row number is from
tableH-template.xsl,
which is posted in
http://sources.redhat.com/ml/xsl-list/2001-09/msg01408.html
and are not repeated here.
Enjoy it.

****  xlst list  ***
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:output method="html"/>
<xsl:include href="tableH-template.xsl"/>

<xsl:variable name="source" select="/calls/call"/>
<xsl:variable name="lines"  select="/calls/line"/>
<xsl:variable name="totals"  select="count($lines)"/>

<xsl:template match="/">
<xsl:call-template name="datasource">
<xsl:with-param name="start" select="1"/>
<xsl:with-param name="lineno" select="1"/>
</xsl:call-template>
</xsl:template>

<xsl:template name="datasource">
<xsl:param name="start" select="1"/>
<xsl:param name="lineno" select="1"/>
<xsl:if test="$lineno &lt;= $totals">
<xsl:variable name="group-size" select="$lines[$lineno]" />
<xsl:variable name="row-size" select="$lines[$lineno]/@row" />
<table><caption><xsl:value-of select="concat('Table',' ',
$lineno)"/></caption>

<!--   using the core listing to group each set of  call element from start
to  start + group-size  - 1 -->
<xsl:apply-templates select="$source[position() &gt;= $start and position()
&lt;= $start + $group-size - 1]" mode="multiColumn">
      <xsl:with-param name="nodes" select="$source[position() &gt;= $start
and position() &lt;= $start + $group-size - 1]"/>
      <xsl:with-param name="numCols" select="$row-size"/>
    </xsl:apply-templates>
</table>
<xsl:call-template name="datasource">
<xsl:with-param name="start" select="$start + $group-size"/>
<xsl:with-param name="lineno" select="$lineno + 1"/>
</xsl:call-template>
</xsl:if>
</xsl:template>

</xsl:stylesheet>
***   xml  ***
<calls>
 <line row="2">3</line>
 <line row="3">4</line>
 <line row="4">5</line>
 <call>sme text1</call>
 <call>sme text2</call>
 <call>sme text3</call>
 <call>sme text4</call>
 <call>sme text5</call>
 <call>sme text6</call>
 <call>sme text7</call>
 <call>sme text8</call>
 <call>sme text9</call>
 <call>sme text10</call>
 <call>sme text11</call>
</calls>


Sun-fu Yang

sfyang@xxxxxxxxxxxxx




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


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

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.
Email
First Name
Last Name
Company
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.