[XSL-LIST Mailing List Archive Home]
[By Thread]
[By Date]
Re: [xsl] Re: (Probably trivial) grouping problem
Subject: Re: [xsl] Re: (Probably trivial) grouping problem From: "Stefan Tilkov" <stefan.tilkov@xxxxxxxxx> Date: Sat, 19 Jul 2003 13:24:07 +0200 |
Thank you very much indeed - works like a charm. Stefan owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx wrote on 19.07.2003 12:38:50: > Use the following transformation: > > <xsl:stylesheet version="1.0" > xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> > > <xsl:output omit-xml-declaration="yes" indent="yes"/> > > <xsl:strip-space elements="*"/> > > <xsl:key name="kFollParas" match="para[not(@title)]" > use="generate-id(preceding-sibling::para[@title][1])"/> > > <xsl:template match="para[@title]"> > <section> > <title><xsl:value-of select="@title"/></title> > <para><xsl:value-of select="."/></para> > <xsl:copy-of select="key('kFollParas', generate-id())"/> > </section> > </xsl:template> > <xsl:template match="para[not(@title)]"/> > </xsl:stylesheet> > > > When applied on your source.xml: > > <text> > <para title="title1"> > some text > </para> > <para> > a para without a title > </para> > <para title="title2"> > more text > </para> > <para> > yet another untitled para > </para> > </text> > > > the wanted result is produced: > > <section> > <title>title1</title> > <para> > some text > </para> > <para> > a para without a title > </para> > </section> > <section> > <title>title2</title> > <para> > more text > </para> > <para> > yet another untitled para > </para> > </section> > > > Hope this helped. > > > ===== > Cheers, > > Dimitre Novatchev. > http://fxsl.sourceforge.net/ -- the home of FXSL > > "Stefan Tilkov" <stefan.tilkov@xxxxxxxxx> wrote in message > news:OFF1F431D7.102B9DE9-ONC1256D68.002AEF58-C1256D68.002AFA73@xxxxxxxxxxxx > > I can't for the life of me figure out how to solve a simple problem. I > > know that it is related to grouping, but my XSL (and XPath) knowlegde is > > not up to translating answers given to similar problems to my particular > > case. > > > > I have a couple of paragrahps, marked up this way: > > > > <para title="title1"> > > some text > > </para> > > <para> > > a para without a title > > </para> > > <para title="title2"> > > more text > > </para> > > <para> > > yet another untitled para > > </para> > > > > I want to turn them into this: > > > > <section> > > <title>title1</title> > > <para> > > some text > > </para> > > <para> > > a para without a title > > </para> > > </section> > > <section> > > <title>title2</title> > > <para> > > more text > > </para> > > <para> > > yet another untitled para > > </para> > > </section> > > > > That is, I want to create sections from paragraphs, turning the title into > > an element belonging to the section. My experiments with following-sibling > > and preceeding-sibling all had the problem that *all* paragraphs without a > > title were returned, and I somehow need to get access to only those before > > the next para with a title. > > > > Any help would be greatly appreciated. > > > > Stefan > > > > XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list > > > > > > > > > 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] Re: (Probably trivial) groupi, Dimitre Novatchev | Thread | [xsl] grouping and word counting, marina |
[xsl] Re: (Probably trivial) groupi, Dimitre Novatchev | Date | [xsl] Re: grouping and word countin, Dimitre Novatchev |
Month |
Keywords