Subject: [xsl] Re: A grouping question ? From: "Dimitre Novatchev" <dnovatchev@xxxxxxxxx> Date: Fri, 31 Oct 2003 18:44:03 +0100 |
Hi Emilio, This 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="kList" match="Paragraph[@bullet='true']" use="generate-id(preceding-sibling::Paragraph [not(@bullet='true')][1] )"/> <xsl:template match="Content"> <html> <xsl:apply-templates select="node()[not(self::Paragraph and @bullet='true')]"/> </html> </xsl:template> <xsl:template match="Paragraph[not(@bullet='true')]"> <p><xsl:value-of select="Text/@txt"/></p> <xsl:if test="following-sibling::Paragraph [@bullet='true']"> <ul> <xsl:apply-templates select="key('kList', generate-id())"/> </ul> </xsl:if> </xsl:template> <xsl:template match="Paragraph[@bullet='true']"> <li><xsl:value-of select="Text/@txt"/></li> </xsl:template> </xsl:stylesheet> when aplied on your source.xml: <Content> <Paragraph bullet='false'> <Text txt='Hello World'/> </Paragraph> <Paragraph bullet='true'> <Text txt='First Bulleted Hello World'/> </Paragraph> <Paragraph bullet='true'> <Text txt='Second Bulleted Hello World'/> </Paragraph> <Paragraph bullet='false'> <Text txt='A normal line of text'/> </Paragraph> <Paragraph bullet='true'> <Text txt='Another bulleted line'/> </Paragraph> <Paragraph bullet='true'> <Text txt='A second bulleted line'/> </Paragraph> </Content> produces the wanted result: <html> <p>Hello World</p> <ul> <li>First Bulleted Hello World</li> <li>Second Bulleted Hello World</li> </ul> <p>A normal line of text</p> <ul> <li>Another bulleted line</li> <li>A second bulleted line</li> </ul> </html> Hope this helped. ===== Cheers, Dimitre Novatchev. http://fxsl.sourceforge.net/ -- the home of FXSL "Emilio Gustavo Ormeño" <eormeno@xxxxxxxxxxxxxxxxx> wrote in message news:3FA256EB.4050008@xxxxxxxxxxxxxxxxxxxx > Hi, I don't know if this is a grouping question, but given than I don't > know the way to solve it. I need your help. This is my problem: > > I have a XML file such as: > > <Content> > <Paragraph bullet='false'> > <Text txt='Hello World'/> > </Paragraph> > <Paragraph bullet='true'> > <Text txt='First Bulleted Hello World'/> > </Paragraph> > <Paragraph bullet='true'> > <Text txt='Second Bulleted Hello World'/> > </Paragraph> > <Paragraph bullet='false'> > <Text txt='A normal line of text'/> > </Paragraph> > <Paragraph bullet='true'> > <Text txt='Another bulleted line'/> > </Paragraph> > <Paragraph bullet='true'> > <Text txt='A second bulleted line'/> > </Paragraph> > </Content> > > And I want an HTML output like the following: > > <html> > <p>Hello World</p> > <ul> > <li>First Bulleted Hello World</li> > <li>Second Bulleted Hello World</li> > </ul> > <p>A normal line of text</p> > <ul> > <li>Another bulleted line</li> > <li>A second bulleted line</li> > </ul> > </html> > > I thought that it was a grouping problem, but when I tried to solve it, > I realized that this is not a "normal" grouping problem. > > Can someone tell me a way to solve it -- if it exists.... > > Thanks > Emilio > > > 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 -> |
---|---|---|
Re: [xsl] A grouping question ?, Richard Lewis | Thread | RE: [xsl] A grouping question ?, Américo Albuquerque |
Re: [xsl] XSLT Parameter error in A, Richard Lewis | Date | Re: [xsl] Handling Duplicate Lines , Murali Korrapati |
Month |