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

Re: converting html table to xml

Subject: Re: converting html table to xml
From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx>
Date: Fri, 29 Nov 2002 16:40:49 +0000
html table to xml
Hi Thomas,

> I have an html table that looks like the one included below. I want
> to convert it to an xml file that looks like the one shown below. I
> haven't had much luck, but I have included my xsl attempt below, but
> it doesn't quite get me what I am looking for.
>
> Here is the sample xml
> <table>
> <tr>
>         <td><a>lateletters</a></td>
>         <td>xx</td>
> </tr>
> <tr>
>         <td>yy</td>
>         <td>zz</td>
> </tr>
> <tr>
>         <td><a>earlyletters</a></td>
>         <td>aa</td>
> </tr>
> <tr>
>         <td>bb</td>
>         <td>cc</td>
> </tr>
> </table>
>
> Here is what I want the output to look like
> <frag>
> <letters name="lateletters">
> <letter>xx</letter>
> <letter>yy</letter>
> <letter>zz</letter>
> </letters>
> <letters name="earlyletters">
> <letter>aa</letter>
> <letter>bb</letter>
> <letter>cc</letter>
> </letters>
> </frag>

Your problem is how to get the <td> elements containing the letters
that belong to one of your letter groups. I think that the easiest way
to do this is to set up a key that indexes each <td> element that
doesn't contain an <a> element by the value of the closest preceding
<a> element, which you can do with:

<xsl:key name="letters" match="td[not(a)]"
         use="preceding::a[1]" />

The XSLT then looks similar to what you have already, except that you
can use the key to get at the letters associated with each letter
group:

  <xsl:for-each select="tr/td/a">
    <letters name="{.}">
      <xsl:for-each select="key('letters', .)">
        <letter><xsl:value-of select="."/></letter>
      </xsl:for-each>
    </letters>
  </xsl:for-each>

Cheers,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/


 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.