This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: structuring templates to generate html tables
- From: "cutlass" <cutlass at secure0 dot com>
- To: <xsl-list at lists dot mulberrytech dot com>
- Date: Tue, 23 Apr 2002 18:22:45 +0100
- Subject: Re: [xsl] structuring templates to generate html tables
- References: <00d101c1eae6$01d15c00$b4c809c0@LKWHBSW2K0335>
- Reply-to: xsl-list at lists dot mulberrytech dot com
Hello Andrew,
your best bet is 2 have a 2 stage transformation, you are trying to do too
much in one transform.
a) serialise all text nodes into a simple <root><element/></root> using
tokenise methods
b) then do your template matching and numbering
otherwise u will pull your hair out
gl, jim fuller
----- Original Message -----
From: "Andrew Welch" <awelch@piper-group.com>
To: "Xsl-List (E-mail)" <xsl-list@lists.mulberrytech.com>
Sent: Tuesday, April 23, 2002 5:43 PM
Subject: [xsl] structuring templates to generate html tables
>
> Hi list,
>
> I have a problem with trying to create a table from nested data. The data
> is nested as follows:
>
> <root>
> <para0>
> <para>apple</para>
> <subpara1>
> <para>orange</para>
> <subpara2>
> <para>bannana</para>
> </subpara2>
> </subpara1>
> </para0>
> </root>
>
> The output I need is like this:
>
> <table>
> <tr><td>1</td><td>apple</td></tr>
> <tr><td>2</td><td>orange</td></tr>
> <tr><td>3</td><td>bannana</td></tr>
> </table>
>
> Simple enough so far, but para0, subpara1 etc can contain any nodes. For
> example, this xsl will give me the output I need above:
>
> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
> version="1.0">
>
> <xsl:template match="/">
> <xsl:apply-templates/>
> </xsl:template>
>
> <xsl:template match="root/para0">
> <table>
> <xsl:apply-templates/>
> </table>
> </xsl:template>
>
> <xsl:template match="subpara1|subpara2">
> <xsl:apply-templates/>
> </xsl:template>
>
> <xsl:template match="para">
> <tr>
> <td><xsl:value-of select="count(preceding::para|.)"/></td>
> <td><xsl:apply-templates/></td>
> </tr>
> </xsl:template>
> </xsl:stylesheet>
>
> I could have a <randlist> element in my example above, with the template
for
> it looking something like this:
>
> <xsl:template match="randlist">
> <ul>
> <xsl:for-each select="item">
> <li><xsl:apply-templates/></li>
> </xsl:for-each>
> </ul>
> </xsl:template>
>
> This element can occur within any element (just like <para>), but for it
to
> work with the example above it would need to be wrapped in <tr><td>'s. I
> have 100's of elements to deal with, so having two templates for each
> element (ie one for within table, one for outside) isn't an option. How
can
> I structure my templates above to allow any element in the table (with the
> template working just as well outside of the table)?
>
>
> Apologies to anyone who doesn't understand my poor explanation, but
> hopefully someone will ;)
>
> cheers
> andrew
>
>
>
>
>
>
>
> ************************************************************************
> *<a href="http://www.thebristoldirectory.com" >The Bristol Directory</a>*
> ************************************************************************
>
> ---
> Outgoing mail is certified Virus Free.
> Checked by AVG anti-virus system (http://www.grisoft.com).
> Version: 6.0.350 / Virus Database: 196 - Release Date: 17/04/2002
>
>
>
> XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
>
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list