xsl-list
[Top] [All Lists]

RE: Re: output in table

2005-06-20 13:14:17
The answer is the same no matter how many rows you plan to have. The details 
are slightly different depending on the number of columns you wish to display. 
You will need to use the mod operator in conjunction with the position() 
function to create a new row where you want one.

Sic,

<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
  <xsl:output method="xml" indent="yes" encoding="UTF-8" />
  <xsl:strip-space elements="*" />

  <xsl:template match="/">
    <xsl:apply-templates />
  </xsl:template>

  <xsl:template match="root">
    <table border="1">
      <xsl:apply-templates />
    </table>
  </xsl:template>

  <xsl:template match="carrier">
    <xsl:choose>
      <xsl:when test="count(preceding-sibling::carrier)mod 3=0">
        <tr>
          <td><xsl:value-of select="@name" /></td>
          <td><xsl:value-of select="following-sibling::carrier[1]/@name" /></td>
          <td><xsl:value-of select="following-sibling::carrier[2]/@name" /></td>
        </tr>
      </xsl:when>
      <xsl:otherwise />
    </xsl:choose>
  </xsl:template>

</xsl:stylesheet>
-- 
Charles Knell
cknell(_at_)onebox(_dot_)com - email



-----Original Message-----
From:     Charles Ohana <charles(_dot_)ohana(_at_)buongiorno(_dot_)com>
Sent:     Mon, 20 Jun 2005 11:40:02 -0500
To:       <xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com>
Subject:  Re: [xsl] output in table

I need the following output. But I need it generic since I don't know how 
many element I'm going to have ...
- Thanx

<table border="1">
   <tr>
      <td> cingular </td>
      <td> t-mobile </td>
      <td> att </td>
   </tr>
      <td> verizon </td>
      <td> nextel </td>
      <td> sprint </td>
   </tr>
      <td> boost </td>
      <td> Other </td>
      <td> Unknown </td>
   </tr>
</table>

<root>
   <carrier name="cingular" position="1" />
   <carrier name="t-mobile" position="2" />
   <carrier name="att" position="0" />
   <carrier name="verizon" position="3" />
   <carrier name="nextel" position="4" />
   <carrier name="sprint" position="5" />
   <carrier name="boost" position="6" />
   <carrier name="Other" position="7" />
   <carrier name="Unknown" position="7" />
</root>




----- Original Message ----- 
From: <cknell(_at_)onebox(_dot_)com>
To: <xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com>
Sent: Monday, June 20, 2005 10:23 AM
Subject: RE: [xsl] output in table


You have given us half of the information we need, now show us the output 
you would like to produce from this XML and we can show you how to write 
the XSLT.
-- 
Charles Knell
cknell(_at_)onebox(_dot_)com - email



-----Original Message-----
From:     Charles Ohana <charles(_dot_)ohana(_at_)buongiorno(_dot_)com>
Sent:     Mon, 20 Jun 2005 11:21:46 -0500
To:       <xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com>
Subject:  [xsl] output in table

Hello,
I'm trying to have an output of the xml below in a table with 3 rows and 3
columns.
Is there a quick and easy way to do it ...
Thanx ...

<root>
<carrier name="cingular" position="1" />
<carrier name="t-mobile" position="2" />
<carrier name="att" position="0" />
<carrier name="verizon" position="3" />
<carrier name="nextel" position="4" />
<carrier name="sprint" position="5" />
<carrier name="boost" position="6" />
<carrier name="Other" position="7" />
<carrier name="Unknown" position="7" />
</root>


--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: 
<mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--




--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: 
<mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--



--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--




--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--



<Prev in Thread] Current Thread [Next in Thread>