This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: loop in creation of table


> I would like to point you to the reference
> 
> http://sources.redhat.com/ml/xsl-list/2001-07/msg01845.html
> 
>  where Dimitre have presented a more generic approach for the type of
> problem.
> 
> Since his xslt is to written for table presentation row by row,
> the xslt  for table which data shown column by column is modified as
> following;

[nice code snipped]

Hi Sung Fu,

I just touched a litle your solution in order  to further simplify it -- several
repeating lines of code and one unnecessary variable have been eliminated:

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

    <xsl:param name="numCols" select="4" />

    <xsl:template match="/">
        <table>
            <xsl:apply-templates mode="multiColumn"
select="/system/subsystem_id[position() &lt;=$numCols]">
                <xsl:with-param name="numCols" select="$numCols" />
                <xsl:with-param name="nodes" select="/system/subsystem_id" />
            </xsl:apply-templates>
        </table>
    </xsl:template>

    <xsl:template mode="multiColumn" match="subsystem_id">
        <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="subsystem_id" mode="normal">
        <td>
            <xsl:value-of select="." />
        </td>
    </xsl:template>
</xsl:stylesheet>


Cheers,
Dimitre Novatchev.






__________________________________________________
Do You Yahoo!?
Listen to your Yahoo! Mail messages from any phone.
http://phone.yahoo.com

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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]