[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

Re: [xsl] Nested lists


Subject: Re: [xsl] Nested lists
From: Michael Müller-Hillebrand <mmh@xxxxxxxxx>
Date: Fri, 1 Nov 2013 17:36:30 +0100

Hi Rick,

Compared to the pain using XSLT1 for a task which XSLT2 can easily handle, the
pain you have to go through if you are forced to change a nice working XSLT2
solution down to XSLT1 is a real PITA.

But anyhow, I know that sometimes we are forced to do ugly stuff. I would not
be trying to use xsl:key for that problem, as keys are more of an index across
a full document and in your situation everything depends on the order of
elements. In XSLT2 you would use xsl:for-each-group, which in XSLT1 sometimes
can be kind-of replicated by "tree walking"
<http://www.dpawson.co.uk/xsl/sect2/N4486.html#d5510e1105>.

As in your example the same class attribute value maybe used for a level 1 or
level 2 list item, it might also be a good idea to do some preprocessing,
because otherwise some XPaths may become really long. I guess I would try to
separate the logic of finding the correct list item level from the step of
adding the required <ul>.

Good luck,

- Michael


Am 31.10.2013 um 21:22 schrieb Rick Quatro <rick@xxxxxxxxxxxxxx>:

> Hi,
>
> I have this for my input XML:
>
> <body>
>  <p class="listintro">ListItem_Bullets:</p>
>  <p class="listitembullets">&#8226; Item 1</p>
>  <p class="listitembullets">&#8226; Item 2</p>
>  <p class="listitembullets">&#8226; Item 3</p>
>  <p class="normal">Paragraph within a list.</p>
>  <p class="listitembullets">&#8226; Item 4</p>
>  <p class="listitembullets">&#8226; Item 5</p>
>  <p class="listitemindented">&#8226; Item 1 indented</p>
>  <p class="listitemindented">&#8226; Item 2 indented</p>
>  <p class="listitembullets">&#8226; Item 6</p>
>  <h2>Indented list starts here:</h2>
>  <p class="listitemindented">&#8226; Item 1 indented</p>
>  <p class="listitemindented">&#8226; Item 2 indented</p>
>  <p class="listitemindented">&#8226; Item 3 indented</p>
>  <p class="normal">Paragraph within a list.</p>
>  <p class="listitemindented">&#8226; Item 4 indented</p>
>  <p class="listitemindented">&#8226; Item 5 indented</p>
>  <p class="listitemindented">&#8226; Item 6 indented</p>
> </body>
>
> I want to get this:
>
> <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</li>
>     <ul>
>       <li>Item 1 indented</li>
>       <li>Item 2 indented</li>
>     </ul>
>     <li>Item 6</li>
>  </ul>
>  <h2>Indented list starts here:</h2>
>  <ul>
>     <li>. Item 1 indented</li>
>     <li>. Item 2 indented</li>
>     <li>. Item 3 indented</li>
>  </ul>
>  <p class="normal">Paragraph within a list.</p>
>  <ul>
>     <li>. Item 4 indented</li>
>     <li>. Item 5 indented</li>
>     <li>. Item 6 indented</li>
>  </ul>
> </body>
>

--
Michael M|ller-Hillebrand
mmh@xxxxxxxxx


Current Thread