LiveDocs : TOC

From: Date: Mon, 02 Jun 2003 20:10:16 +0000
Subject: LiveDocs : TOC
Groups: php.doc 
Request: Send a blank email to phpdoc+get-969354209@lists.php.net to get a copy of this message
Hey, I've been toying with XSLT tonight, which seems the fastest way to generate a TOC for the LiveDocs: it takes only 11 seconds on my box. Attached is the stylesheet and here is how you use it (xmllint is introduced to make it readable :): [derick@kossu phpdoc-all]$ time xsltproc xsl/toc.xsl manual.xml > /tmp/toc.tmp.xml; xmllint --format /tmp/toc.tmp.xml > /tmp/toc.xml real 0m11.196s user 0m10.030s sys 0m1.150s once we have the toc we can parse it into sqllite.. I'm going to use the Nested Set/Visitation model* for that to maximize performance in finding paths and siblings. regards, Derick * http://www.derickrethans.nl/phpperform/talk.html, slide 36-40 -- ------------------------------------------------------------------------- Derick Rethans http://derickrethans.nl/ JDI Media Solutions http://www.jdimedia.nl/ International PHP Magazine http://www.php-mag.net/ -------------------------------------------------------------------------

<?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:template match="book"> <toc> <title> <xsl:value-of select="title"/> </title> <xsl:apply-templates select="bookinfo"/> <xsl:apply-templates select="preface"/> <xsl:apply-templates select="part"/> </toc> </xsl:template> <xsl:template match="bookinfo|preface"> <dir> <xsl:attribute name="title"><xsl:value-of select="title"/></xsl:attribute> </dir> </xsl:template> <xsl:template match="part"> <part> <xsl:attribute name="id"><xsl:value-of select="@id"/></xsl:attribute> <title> <xsl:value-of select="title"/> </title> <xsl:apply-templates select="chapter"/> <xsl:apply-templates select="reference"/> <xsl:apply-templates select="appendix"/> </part> </xsl:template> <xsl:template match="chapter"> <chapter> <xsl:attribute name="id"><xsl:value-of select="@id"/></xsl:attribute> <title> <xsl:value-of select="title"/> </title> <xsl:apply-templates select="sect1|section"/> </chapter> </xsl:template> <xsl:template match="appendix"> <appendix> <xsl:attribute name="id"><xsl:value-of select="@id"/></xsl:attribute> <title> <xsl:value-of select="title"/> </title> <xsl:apply-templates select="sect1"/> </appendix> </xsl:template> <xsl:template match="reference"> <reference> <xsl:attribute name="id"><xsl:value-of select="@id"/></xsl:attribute> <title> <xsl:value-of select="title"/> </title> <xsl:apply-templates select="section|refentry"/> </reference> </xsl:template> <xsl:template match="section"> <sect1> <xsl:attribute name="id"><xsl:value-of select="@id"/></xsl:attribute> <title> <xsl:value-of select="title"/> </title> <xsl:apply-templates select="section"/> </sect1> </xsl:template> <xsl:template match="sect1"> <sect1> <xsl:attribute name="id"><xsl:value-of select="@id"/></xsl:attribute> <title> <xsl:value-of select="title"/> </title> <xsl:apply-templates select="sect2"/> </sect1> </xsl:template> <xsl:template match="sect2"> <sect2> <xsl:attribute name="id"><xsl:value-of select="@id"/></xsl:attribute> <title> <xsl:value-of select="title"/> </title> <xsl:apply-templates select="sect3"/> </sect2> </xsl:template> <xsl:template match="sect3"> <sect3> <xsl:attribute name="id"><xsl:value-of select="@id"/></xsl:attribute> <title> <xsl:value-of select="title"/> </title> <xsl:apply-templates select="sect4"/> </sect3> </xsl:template> <xsl:template match="sect4"> <sect4> <xsl:attribute name="id"><xsl:value-of select="@id"/></xsl:attribute> <title> <xsl:value-of select="title"/> </title> </sect4> </xsl:template> <xsl:template match="refentry"> <chapter> <xsl:attribute name="id"><xsl:value-of select="@id"/></xsl:attribute> <title> <xsl:value-of select="refnamediv/refname"/> </title> </chapter> </xsl:template> </xsl:stylesheet>
« previous php.doc (#969354209) next »