How do I create a table of contents in XSL?

I have an XML file that I am creating an XSL stylesheet for.

I would like to have two frames and make two passes through the data, the first will create a table of contents in the left frame and the second will have the data body on the right.

I can do two passes, the problem is to put them in separate frames. The frame HTML element accepts a source; I cannot post my source right there.

I can think of several ways to get around this, none of which I am in awe of this, so I wanted to see if anyone found a way to do this.

0


source to share


3 answers


As said, you need 3 files for this.

In XSLT 2.0, you can create multiple output files from a single xsl stylesheet using the xsl: result-document statement.



In XSLT 1.0, you don't have this feature, but depending on the processor it is possible. For example for Xalan see http://xml.apache.org/xalan-j/extensions_xsltc.html#redirect_ext

0


source


If you want to use frames, you need three separate files.

  • Frame file. This is just a strict HTML file
  • File for your table of contents
  • File for your content

The first one matches only the HTML file. Secondly, these are XSL files that will eventually turn into HTML. Good HR tutorial here at W3Schools .



EDIT . The more I think about it, the more I dislike the solution. This requires the XSL parser to run twice for every time the start page is served

Have you ever wondered how to use CSS or tables for your layout? There are some really good open source CSS templates that have flown here cross-country.

0


source


This was relatively stable data that would be generated by a script, so I decided to create separate stylesheets for the TOC and main window, and then use the ones that generate the html files for each after the html is generated.

Back then, my main page was just a static html page that linked to these generated html files.

Probably the best way to do this, but this is an internal link, so that's enough to get me moving.

0


source







All Articles