Subject: RE: [xsl] How to create tables from this...? From: "McNally, David" <David.McNally@xxxxxxxxxx> Date: Tue, 23 Apr 2002 13:14:37 -0400 |
Here's one more approach, using keys. Basically we need some way to group together each set of non-paragraph elements for processing into a single table. I do it by giving each of these elements (common | less-common | rare | very-rare) a key equal to the generated id of their first preceding paragraph. So in a consecutive set of these elements, they'll all have the same key. The processing is kicked off by the paragraph template - basically if a paragraph is followed by a non-paragraph, it processes all elements with key equal to it's own generated id. So: <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="html" indent="yes"/> <xsl:key name="npgrouper" match="common | less-common | rare | very-rare" use="generate-id(preceding-sibling::paragraph[1])"/> <xsl:template match="/"> <html> <xsl:apply-templates/> </html> </xsl:template> <xsl:template match="paragraph"> <p> <xsl:apply-templates/> </p> <xsl:if test="following-sibling::*[1][name() != 'paragraph']"> <!-- I assume there aren't any other non paragraph elements floating about, but it would be safer to spell out the names common, less-common, etc --> <table> <xsl:apply-templates select="key('npgrouper',generate-id(.))" mode="output"/> </table> </xsl:if> </xsl:template> <xsl:template match="common | less-common | rare | very-rare" mode="output"> <xsl:copy-of select="."/> </xsl:template> <xsl:template match="common | less-common | rare | very-rare"/> </xsl:stylesheet> Gives me output of: <html> <p>blabla</p> <table> <common> <paragraph>blabla</paragraph> </common> <less-common> <paragraph>blabla</paragraph> </less-common> <rare> <paragraph>blabla</paragraph> <paragraph>blabla</paragraph> </rare> </table> <p>blabla</p> <p>blabla</p> <table> <common> <paragraph>blabla</paragraph> </common> <very-rare> <paragraph>blabla</paragraph> <paragraph>blabla</paragraph> </very-rare> </table> <p>blabla</p> </html> Which I think is what you want. Hope this helps, David. -- David McNally Moody's Investors Service Software Engineer 99 Church St, NY NY 10007 David.McNally@xxxxxxxxxx (212) 553-7475 > -----Original Message----- > From: Emma Larsson [mailto:emma.larsson@xxxxxxxx] > Sent: Tuesday, April 23, 2002 10:45 AM > To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx > Subject: [xsl] How to create tables from this...? > > > Hi, > > Below is a snippet from one of the XML files I am working with. > > <driving/> > <side-effects> > <paragraph>blabla</paragraph> > <common> > <paragraph>blabla</paragraph> > </common> > <less-common> > <paragraph>blabla</paragraph> > </less-common> > <rare> > <paragraph>blabla</paragraph> > <paragraph>blabla</paragraph> > </rare> > <paragraph>blabla</paragraph> > <paragraph>blabla</paragraph> > <common> > <paragraph>blabla</paragraph> > </common> > <very-rare> > <paragraph>blabla</paragraph> > <paragraph>blabla</paragraph> > </very-rare> > <paragraph>blabla</paragraph> > </side-effects> > <overdosage/> > > This is from the DTD: > <!ELEMENT side-effects (paragraph | very-common | common | > less-common | rare | very-rare)* > > > This is what I want to create: > blabla > <table with the elements common, less-common and rare (and > their underlying paragraphs)> > blabla > blabla > <table with the elements common and very-rare (and their > underlying paragraphs)> > blabla > > So, I want to create tables, one table for each set of > elements that are not paragraphs. These sets are > separated by paragraphs and they contain paragraphs that > should be included in the table... Any > suggestions of how to do this? > > /Emma > > > > > XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list > --------------------------------------- The information contained in this e-mail message, and any attachment thereto, is confidential and may not be disclosed without our express permission. If you are not the intended recipient or an employee or agent responsible for delivering this message to the intended recipient, you are hereby notified that you have received this message in error and that any review, dissemination, distribution or copying of this message, or any attachment thereto, in whole or in part, is strictly prohibited. If you have received this message in error, please immediately notify us by telephone, fax or e-mail and delete the message and all of its attachments. Thank you. Every effort is made to keep our network free from viruses. You should, however, review this e-mail message, as well as any attachment thereto, for viruses. We take no responsibility and have no liability for any computer virus which may be transferred via this e-mail message. XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] How to create tables from, Jeni Tennison | Thread | [xsl] Using Struts ApplicationResou, Simpson, George |
Re: [xsl] Newbie XSL Evaluation, cutlass | Date | [xsl] Data structure in XSLT?, Charles Chan |
Month |