[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

Re: [xsl] Creating nested structures


Subject: Re: [xsl] Creating nested structures
From: Wendell Piez <wapiez@xxxxxxxxxxxxxxxx>
Date: Fri, 23 Jan 2004 17:47:49 -0500

Hi Scott,

At 02:31 PM 1/23/2004, you wrote:
your question: "Or is this actually the case, and do you really want your result to have tables inside td (cell) elements? which is common enough in HTML"

Answer is "yes I want to have my results to have tables inside td elements.

I have included a snippet of the html input I parse to the xml structure I listed above. Also <TABLE> = <table>; <DPROW> = <tr>; and <OBJECT> = <td>

input html snippet:

<TABLE BORDER="0" CELLSPACING="0" CELLPADDING="0" WIDTH="842"><TR><TD WIDTH="3"></TD><TD><TABLE WIDTH="100%" BORDER="0" CELLSPACING="0" CELLPADDING="0"><TR HEIGHT="6"><TD WIDTH="4"></TD><TD WIDTH="22"></TD><TD WIDTH="67"></TD><TD WIDTH="2"></TD><TD WIDTH="211"></TD><TD WIDTH="2"></TD><TD WIDTH="273"></TD><TD WIDTH="48"></TD><TD WIDTH="92"></TD><TD WIDTH="2"></TD><TD WIDTH="2"></TD><TD WIDTH="82"></TD><TD WIDTH="6"></TD><TD WIDTH="22"></TD><TD WIDTH="5"></TD></TR><TR><TD WIDTH="4"></TD><TD WIDTH="22"></TD><TD WIDTH="67" VALIGN="TOP"><TABLE BORDER="0" WIDTH="66"><TR><TD CLASS="s2">Agent ID:</TD></TR></TABLE></TD><TD WIDTH="2" COLSPAN="2" VALIGN="TOP"><TABLE BORDER="0" WIDTH="212"><TR><TD CLASS="s3">100008</TD></TR></TABLE></TD><TD WIDTH="2"></TD><TD WIDTH="273"></TD><TD WIDTH="48"></TD><TD WIDTH="92"></TD><TD WIDTH="2"></TD><TD WIDTH="2" COLSPAN="2" VALIGN="TOP"><TABLE BORDER="0" WIDTH="84"><TR><TD CLASS="s4">12/19/2003</TD></TR></TABLE></TD><TD WIDTH="6"></TD><TD WIDTH="22"></TD><TD WIDTH="5"></TD><TD HEIGHT="20"></TD></TR><TR><TD WIDTH="4"></TD><TD WIDTH="22" COLSPAN="3" ROWSPAN="2" VALIGN="TOP"><TABLE BORDER="0" WIDTH="90"><TR><TD CLASS="s2">Agent Name:</TD></TR></TABLE></TD><TD WIDTH="211"></TD><TD WIDTH="2"></TD><TD WIDTH="273"></TD><TD WIDTH="48"></TD><TD WIDTH="92" COLSPAN="3" ROWSPAN="2" VALIGN="TOP"><TABLE BORDER="0" WIDTH="96"><TR><TD CLASS="s4">Report Date:</TD></TR></TABLE></TD><TD WIDTH="82" COLSPAN="3" ROWSPAN="2" VALIGN="TOP"><TABLE BORDER="0"

Sorry, I'm still having to make inferences. You describe the HTML above as input. If this is input to a process which is creating your TABLE/DROW/OBJECT structure, and it's the TABLE/DROW/OBJECT structure that you need to map out again to HTML tables, then what's wrong with the simple XSLT that Jorge suggested and that I included earlier today? (Have you tried it?)


This will map TABLE to table, DPROW to tr and OBJECT to td. TABLE elements that appear inside OBJECT elements in the source will come out as table elements inside td elements in the result. No sweat: this is what XSLT does best; in fact you have to work extra to get it to do differently.

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

<xsl:template match="DPROW"><!-- sorry, earlier I called it "DROW" -->
  <tr>
    <xsl:apply-templates/>
  </tr>
</xsl:template>

<xsl:template match="OBJECT">
  <td>
    <!-- first, whatever you want to do to show empty objects -->
    ...
    <!-- then, continue tree traversal for the data content
         and the nested tables by applying templates -->
    <xsl:apply-templates/>
  </td>
</xsl:template>

(Note again that it does have to be enhanced to handle your attributes; but that's separate from the structural mapping problem.) If you have tried this and it doesn't do what you want, then we still have a problem, since what you say you want is what this code will do (yes, it will create tables inside tds, wherever you have TABLEs inside OBJECTs), so we need to go back to square one: either we haven't understood yet what you want, or the problem is larger than what you have described -- there could be something happening in code you haven't shown us.

Cheers,
Wendell


====================================================================== Wendell Piez mailto:wapiez@xxxxxxxxxxxxxxxx Mulberry Technologies, Inc. http://www.mulberrytech.com 17 West Jefferson Street Direct Phone: 301/315-9635 Suite 207 Phone: 301/315-9631 Rockville, MD 20850 Fax: 301/315-8285 ---------------------------------------------------------------------- Mulberry Technologies: A Consultancy Specializing in SGML and XML ======================================================================


XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list




Current Thread
Keywords