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

Re: loop in creation of table

Subject: Re: loop in creation of table
From: "Yang" <sfyang@xxxxxxxxxxxxx>
Date: Thu, 27 Sep 2001 17:15:06 +0800
xsl loop variable table formatting
Hi, Dimitre

Thanks for your kindness to clean up my xslt redundant codes.
To make this piece of template  be more generic,
a variable **source** is to define the  xml-dependent tree structure.
So the template can be used without further touching, i.e.,
  <xsl:variable name="source" select="/parent-of-subsystem_id/subsystem_id"
/>
and use it as the value of select attribute.  Meantimes the element abbr *
is used
with match. The test seems ok.  But I wonder what might be missing from this
kind
of approach.

Thanks for your comment.

**   modified xslt part code  ***

  <xsl:variable name="source" select="/parent-of-subsystem_id/subsystem_id"
/>
<xsl:template match="/">
        <table>
        <xsl:apply-templates mode="multiColumn"  select="$source[position()
&lt;=$numCols]">

^^^^^^^
          <xsl:with-param name="numCols" select="$numCols"/>
          <xsl:with-param name="nodes" select="$source"/>

^^^^^^^
   </xsl:apply-templates>
        </table>
    </xsl:template>

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

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

        <xsl:variable name="vColour">
            <xsl:choose>
                <xsl:when test="$vCurPosition mod 2 = 1">aqua</xsl:when>
                <xsl:otherwise>red</xsl:otherwise>
            </xsl:choose>
        </xsl:variable>

        <tr bgcolor="{$vColour}">
            <xsl:apply-templates mode="normal"
                 select="$nodes[position() >= $vCurPosition
                     and (position() - $vCurPosition) mod $numCols = 0]" />
        </tr>
    </xsl:template>

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

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.