[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()
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 <= $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() >= $start and position() <= $start + $group-size - 1]" mode="multiColumn"> <xsl:with-param name="nodes" select="$source[position() >= $start and position() <= $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
|
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
|