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

Re: need further assistance with grouping nodes into g

Subject: Re: need further assistance with grouping nodes into groups of 3
From: "Yang" <sfyang@xxxxxxxxxxxxx>
Date: Sun, 30 Sep 2001 10:55:29 +0800
xsl mode multicolumn
Chuck,

Your  problem is of typical group by position.   You can get good
reference from Jeni's site,  dpawson site,  or this xslt post.

A fine tuned shorter and generic Dimitre version (tableH-template.xsl) is
used for your reference.

Changing param numCols and source is only job you have to do.
Besides,  you have to rewrite template with mode="normal"  for more
specific information.

The code also allows alternatively coloring on the changing group.
Enjoy it.

***  xslt list  ***
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:output indent="yes"/>
<xsl:include href="tableH-template.xsl"/>
  <xsl:param name="numCols" select="3" />
  <xsl:variable name="source" select="/images/image" />

<xsl:template match="/">

<xsl:apply-templates select="$source" mode="multiColumn">
      <xsl:with-param name="nodes" select="$source"/>
      <xsl:with-param name="numCols" select="$numCols"/>
    </xsl:apply-templates>
</xsl:template>


<xsl:template match="*" mode="normal">
    <td>
        Path: <a href="{thumbimage/thumbpath}">
            <xsl:value-of select="thumbimage/thumbformat"/></a><br/>
        <xsl:for-each select="*[name()!='thumbimage']">
        <xsl:value-of select="concat(name(),':', substring(.,1,25))"/><br/>
        </xsl:for-each>

    </td>
</xsl:template>

</xsl:stylesheet>

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output omit-xml-declaration="yes"/>

    <xsl:template match="*" mode="multiColumn">
      <xsl:param name="nodes" select="/.."/>
      <xsl:param name="numCols" select="1"/>


       <xsl:variable name="vCurPosition" select="position()"/>

<!--   output the table row when test =1  -->

        <xsl:if test="$vCurPosition mod $numCols = 1">
<table>
 <!--  alternative coloring for odd/even row -->
 <xsl:variable name="color">
            <xsl:choose>
                <xsl:when test="$vCurPosition mod (2 * $numCols) =
1">aqua</xsl:when>
                <xsl:otherwise>red</xsl:otherwise>
            </xsl:choose>
 </xsl:variable>

          <tr bgcolor="{$color}">
            <xsl:apply-templates mode="normal"
                                     select="$nodes
                                 [position() >= $vCurPosition
                                 and
                                  position() &lt; $vCurPosition +
$numCols]"/>
          </tr>
</table>
        </xsl:if>
    </xsl:template>

    <xsl:template match="*" mode="normal">
     <td><xsl:value-of select="."/></td>
    </xsl:template>
</xsl:stylesheet>

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.