Subject: Re: [xsl] structuring templates to generate html tables From: "cutlass" <cutlass@xxxxxxxxxxx> Date: Tue, 23 Apr 2002 18:22:45 +0100 |
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@xxxxxxxxxxxxxxx> To: "Xsl-List (E-mail)" <xsl-list@xxxxxxxxxxxxxxxxxxxxxx> 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
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] structuring templates to gene, Andrew Welch | Thread | [xsl] Data structure in XSLT?, Charles Chan |
[xsl] Data structure in XSLT?, Charles Chan | Date | Re: [xsl] passing parameter to an X, Joerg Heinicke |
Month |