|
[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: A grouping question ?
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
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|

Cart








