Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: Generating 2x2 table

From: "Derek Harmon" <loresayer@---.--->
To: NULL
Date: 1/3/2006 12:07:00 AM
"cardinallijr" <cardinallijr@g...> wrote in message news:1136176088.856961.198100@g......
> Hi all, sorry about the simple question but I'm new to XSL. I have a
> XML with 4 elements,
:    :
> What I want to do is to generate a HTML table with 2 columns(2
> products) in each row.

Try the following stylesheet,

- - - TwoByTwo.xsl
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" >

<xsl:template match="/">
    <html>
        <head>
            <title>Demo 2x2 Table</title>
        </head>
        <body bgcolor='lightgray'>
            <table>
                <xsl:apply-templates select="/root/products/product[position() mod 2 = 1]" />
            </table>
        </body>
    </html>
</xsl:template>

<xsl:template match="/root/products/product[position() mod 2 = 1]">
    <tr>
        <td>Product <xsl:value-of select="id" /></td>
        <td>Product <xsl:value-of select="following-sibling::product/id"/></td>
    </tr>
</xsl:template>

</xsl:stylesheet>
-- 

Takeaway from this is that you match on the first (leftmost) product in each row by
looking for the product in a position whose remainder is 1 after dividing by the
desired number of columns (in this case, 2).

This template is responsible for all products grouped into that row.  You can use
XPath's following-sibling:: axis to reach successive products' content to pull it into
this template and make that content part of the cells you render in the same row.


Derek Harmon




transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent