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

Re: Reformatting tables

Subject: Re: Reformatting tables
From: Jörg Heinicke <joerg.heinicke@xxxxxx>
Date: Thu, 29 Nov 2001 15:30:34 +0100
reformatting html tables positions
A more generic version for more than 2 columns:

<xsl:template match="tr">
    <xsl:for-each select="td[1]/p">
        <xsl:variable name="pos" select="position()"/>
        <tr>
            <td><xsl:copy-of select="."/></td>
            <xsl:for-each select="../following-sibling::td">
                <td><xsl:copy-of select="p[$pos]"/></td>
            </xsl:for-each>
        </tr>
    </xsl:for-each>
</xsl:template>

I only made a little test - hope it works.

Regards,

Joerg



Neil Abraham wrote:

Hi all,

I have a large number of html tables in the following format:

<table>
  <tr>
    <td>
      <p>Animal</p>
    </td>
    <td>
      <p>Colour</p>
    </td>
  </tr>
  <tr>
    <td>
      <p>Elephant</p>
      <p>Pig</p>
      <p>Sheep</p>
      <p>Canary</p>
    </td>
    <td>
      <p>Grey</p>
      <p>Pink</p>
      <p>White</p>
      <p>Yellow</p>
    </td>
  </tr>
</table>

Where someone has used FrontPage or something and has ended up creating one
row of multiple paragraphs instead of a row for each item.

How can I write some xsl to reformat this into proper rows? Eg:

<tr>
  <td>
   <p>Elephant</p>
  </td>
  <td>
   <p>Grey</p>
  </td>
</tr>

So far I have made:

<xsl:template match="tr">
 <xsl:for-each select="td[1]/p">
  <tr>
   <td><p><xsl:value-of select="."/></p></td>
   <xsl:variable name="n" select="position()"/>
   <td><p><xsl:value-of select="//td[2]/p[position()=$n]"/></p></td>
  </tr>
 </xsl:for-each>
</xsl:template>

But this always leaves them out of sync.

What am I doing wrong?


Thanks in advance,



Neil.


PS. Excuse the animal colours example, the real data is confidential
internal stuff :-)


--

System Development
VIRBUS AG
Fon  +49(0)341-979-7411
Fax  +49(0)341-979-7409
joerg.heinicke@xxxxxxxxx
www.virbus.de

News:
Cocoon-Premiere - Virbus AG setzt bei ShoppingMall-Plattform "Lofex"
auf neueste XML-basierende Technologie
http://www.virbus.de/de/press/pressemitteilung/20011123_lofex/index.html
http://www.lofex.de


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.