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

RE: Flat List to HTML Table

Subject: RE: Flat List to HTML Table
From: Pieter Reint Siegers Kort <pieter.siegers@xxxxxxxxxxx>
Date: Mon, 25 Oct 2004 19:04:58 -0500
html select flat
Hi Peter,

Take a look at the following stylesheet - it may well give you some ideas on
how to solve your problem:

***********************************
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" exclude-result-prefixes="msxsl local xql"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:local="#local-functions"
xmlns:xql="#xql-functions">

<xsl:output method="xml" indent="yes" omit-xml-declaration="yes"/>

<xsl:template match="/">
	<html>
	<head>
	<title>alternating rows</title>
	</head>
	<body bgcolor="#efc6ff">
		<table border="1">
		<tr><td>
		<table border="1" cellpadding="3" cellspacing="0"
width="600">
			<tr>
				<th align="left" bgcolor="Lightblue"><font
color="white">name</font></th>
				<th align="left" bgcolor="Lightblue"><font
color="white">value</font></th>
				<th align="left" bgcolor="Lightblue"><font
color="white">name</font></th>
				<th align="left" bgcolor="Lightblue"><font
color="white">value</font></th>
			</tr>
			<xsl:apply-templates select="list/item"/>
		</table>
		</td></tr>
		</table>
	</body>
	</html>
</xsl:template>

<xsl:template match="item">
    <xsl:choose>
      <xsl:when test="position() mod 2 = 0">
      </xsl:when>
      <xsl:otherwise>
	  <tr>
		<xsl:attribute name="bgcolor">
        <xsl:choose>
          <xsl:when test="position() mod 2 = 0">#ccfec7</xsl:when>
          <xsl:otherwise>#feffc6</xsl:otherwise>
        </xsl:choose>
        </xsl:attribute>
		<td>
			<xsl:value-of select="@name"/>
		</td>
		<td>
			<xsl:value-of select="."/>
		</td>
		<td>
        <xsl:choose>
          <xsl:when test="following-sibling::item/@name">
			<xsl:value-of
select="following-sibling::item/@name"/>
          </xsl:when>
          <xsl:otherwise>
          &#160;
          </xsl:otherwise>
        </xsl:choose>
		</td>
		<td>
        <xsl:choose>
          <xsl:when test="following-sibling::item/.">
			<xsl:value-of select="following-sibling::item/."/>
          </xsl:when>
          <xsl:otherwise>
          &#160;
          </xsl:otherwise>
        </xsl:choose>
		</td>
	  </tr>
      </xsl:otherwise>
    </xsl:choose>
</xsl:template>

</xsl:stylesheet>
***********************************

HTH,
<prs/> 

-----Original Message-----
From: Peter Charles [mailto:petefc@xxxxxxxxxxxxxxxxx] 
Sent: Monday, October 25, 2004 5:02 PM
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject:  Flat List to HTML Table

Hello,

If I have a list that looks like this:

<list>
    <item name="name1">value1</item>
    <item name="name2">value2/item>
    <item name="name3">value3</item>
    <item name="name4">value4</item>
    <item name="name5">value5</item>
    <item name="name6">value6</item>
    <item name="name7">value7</item>
    <item name="name8">value</item>
    <item name="name9">value9</item>
</list>

And  I want to turn it into a table that looks like this;

<table>
    <tr>
        <td>name1</td>
        <td>value1</td>
        <td>name2</td>
        <td>value2</td>
    </tr>
    <tr>
        <td>name3</td>
        <td>value3</td>
        <td>name4</td>
        <td>value4</td>
    </tr>
    <tr>
        <td>name5</td>
        <td>value5</td>
        <td>name6</td>
        <td>value6</td>
    </tr>
    <tr>
        <td>name7</td>
        <td>value7</td>
        <td>name8</td>
        <td>value8</td>
    </tr>
    <tr>
        <td>name9</td>
        <td>value9</td>
    </tr>
</table>

Can any one suggest a good method for doing so?  I thought about using
template match patterns of:

<xsl:template match="item[position() mod 2=0]">

And
<xsl:template match="item[position() mod 2!=0]">

to let me know if list item is the beginning or ending of a row but that
does not solve the problem of how/when to open and close rows.

Thanks

Peter

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.