Subject: RE: [xsl] Nested lists From: "Rick Quatro" <rick@xxxxxxxxxxxxxx> Date: Fri, 1 Nov 2013 09:48:12 -0400 |
I just about have this working. Here is my input: <?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <!-- generated by DCL filter dwhtm, Ver 4.1 m210 h293 --> <head> <title>Discovering Applications</title> </head> <body> <p class="listintro">ListItem_Bullets:</p> <p class="listitembullets">Item 1</p> <p class="listitembullets">Item 2</p> <p class="listitembullets">Item 3</p> <p class="normal">Paragraph within a list.</p> <p class="listitembullets">Item 4</p> <p class="listitembullets">Item 5</p> <p class="listitemindented">Item 1 indented</p> <p class="listitemindented">Item 2 indented</p> <p class="listitembullets">Item 6</p> <p class="listitemindented">Item 1 indented</p> <p class="listitemindented">Item 2 indented</p> <p class="listitemindented">Item 3 indented</p> </body> </html> Here is my output: <?xml version="1.0" encoding="UTF-8"?> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <!-- generated by DCL filter dwhtm, Ver 4.1 m210 h293 --> <head> <title>Discovering Applications</title> </head> <body> <p class="listintro">ListItem_Bullets:</p> <ul> <li>Item 1</li> <li>Item 2</li> <li>Item 3</li> </ul> <p class="normal">Paragraph within a list.</p> <ul> <li>Item 4</li> <li>Item 5<ul type="circle"> <li>Item 1 indented</li> <li>Item 2 indented</li> </ul> </li> </ul> </body> </html> After my indented list, I lose any "listitembullets" after that. Here is my 1.0 stylesheet. (Sorry, in my development environment, I still have to use a quill pen.) <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns="http://www.w3.org/1999/xhtml" exclude-result-prefixes="xhtml xsl" version="1.0"> <xsl:key name="orderedlists" match="xhtml:p[@class='listitem1' or @class='listitem2']" use="generate-id((..|preceding-sibling::*[not(self::xhtml:p[@class='listitem 1' or @class='listitem2'])][1])[last()])"/> <xsl:key name="unorderedlists-plain" match="xhtml:p[@class='listitemunordered']" use="generate-id((..|preceding-sibling::*[not(self::xhtml:p[@class='listitem unordered'])][1])[last()])"/> <xsl:key name="unorderedlists" match="xhtml:p[@class='listitembullets']" use="generate-id((..|preceding-sibling::*[not(self::xhtml:p[@class='listitem bullets'])][1])[last()])"/> <xsl:key name="unorderedlists-indented" match="xhtml:p[@class='listitemindented']" use="generate-id((..|preceding-sibling::*[not(self::xhtml:p[@class='listitem indented'])][1])[last()])"/> <xsl:output indent="yes"/> <!--this is a construct whose children need to be grouped in separate lists--> <xsl:template match="xhtml:body"> <body> <xsl:apply-templates mode="group" select=".|*[not(self::xhtml:p[@class='listitem1' or @class='listitem2' or @class='listitemunordered' or @class='listitembullets' or @class='listitemindented'])]"/> </body> </xsl:template> <xsl:template mode="group" match="*"> <xsl:apply-templates select="self::*[not(self::xhtml:body)]"/> <xsl:if test="key('orderedlists',generate-id(.))"> <ol start="{substring-before(following-sibling::*/node(),'.')}"> <xsl:apply-templates select="key('orderedlists',generate-id(.))"/> </ol> </xsl:if> <xsl:if test="key('unorderedlists-plain',generate-id(.))"> <dl> <xsl:apply-templates select="key('unorderedlists-plain',generate-id(.))"/> </dl> </xsl:if> <xsl:if test="key('unorderedlists-indented',generate-id(.))"> <ul> <xsl:apply-templates select="key('unorderedlists-indented',generate-id(.))"/> </ul> </xsl:if> <xsl:if test="key('unorderedlists',generate-id(.))"> <ul> <xsl:apply-templates select="key('unorderedlists',generate-id(.))"/> </ul> </xsl:if> </xsl:template> <!--the following template rules need no knowledge of grouping--> <xsl:template match="xhtml:p[@class='listitem1' or @class='listitem2']"> <li><xsl:apply-templates/></li> </xsl:template> <xsl:template match="xhtml:p[@class='listitem1' or @class='listitem2']/text()[1]"> <xsl:value-of select="substring-after(.,'. ')"/> </xsl:template> <xsl:template match="xhtml:p[@class='listitembullets' or @class='listitemindented']"> <li><xsl:apply-templates/> <xsl:if test="key('unorderedlists-indented',generate-id(.))"> <ul type='circle'> <xsl:apply-templates select="key('unorderedlists-indented',generate-id(.))"/> </ul> </xsl:if></li> </xsl:template> <xsl:template match="xhtml:p[@class='listitemunordered']"> <dd><xsl:apply-templates/></dd> </xsl:template> <xsl:template match="xhtml:p[@class='listitembullets']/text()[1]"> <xsl:value-of select="substring-after(.,'• ')"/> </xsl:template> <!-- IdentityTransform --> <xsl:template match="/ | @* | node()" name="identity"> <xsl:copy><xsl:apply-templates select="@* | node()" /></xsl:copy> </xsl:template> </xsl:stylesheet>
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] Nested lists, Martin Honnen | Thread | Re: [xsl] Nested lists, Michael Müller-Hille |
Re: [xsl] Nested lists, Martin Honnen | Date | Re: [xsl] Nested lists, Michael Müller-Hille |
Month |