How-to: Dividing Content by Headlines
This is an open discussion with 2 replies, filed under XSLT.
Search
Nice, that is exactly what i had on the backburner in this thread. something tells me this would be quite impossible to apply to a horizontal brake tag, because its a single self closing tag...or can it be done?
Nice.
You can easily extend this to create a table of contents by placing named anchors at each headline, and recreating the headlines as links to those anchors in a different mode.
thanks for the post Nils!
Create an account or sign in to comment.
Task
For a project I'm currently working on, I needed to divide the content of an entry into multiple divs.
I'm using Markdown so the text itself was entered like this:
The result was the following html:
But what I needed was this:
Solution
As I think this is common problem to solve, I like to post my solution.
First of all I created a template that applied to all headlines:
And a second template that matched these headlines:
First of all I wanted the template to just show the headline:
Secondly I wrapped the headlines with the needed divs:
The only thing missing was the content between two headlines:
To keep all elements between two headlines (instead of just getting their text nodes) I used some advanced XSL manipulations Allen once described in his blog and added:
That's it! Hope this might be helpful for others.
Nils