Förvandla toc.ncx till toc.html

$ xsltproc -o toc.html ncx2html.xsl toc.ncx
$ perl -Cio -pi -e 's/([^\x00-\x7f])/sprintf("&#%d;", ord($1))/ge;' toc.html

<?xml version="1.0" encoding="ISO-8859-1"?>
<!-- ncx2html: An (incomplete) XML stylesheet to transform NCX to HTML. -->
<xsl:stylesheet version="1.0"
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                xmlns:ncx="http://www.daisy.org/z3986/2005/ncx/">
<xsl:output method="xml" indent="yes"/>

<xsl:template match="/ncx:ncx">
  <html>
    <body>
      <h1><xsl:value-of select="ncx:docTitle/ncx:text"/>: Contents</h1>
      <p>
        <xsl:if test="ncx:navMap/ncx:navPoint">
          <ul>
            <xsl:apply-templates select="ncx:navMap/ncx:navPoint"/>
          </ul>
        </xsl:if>
      </p>
    </body>
  </html>
</xsl:template>

<xsl:template match="ncx:navPoint">
  <li>
    <a href="{ncx:content/@src}">
      <xsl:value-of select="ncx:navLabel"/>
    </a>
    <br/>
    <xsl:if test="ncx:navPoint">
      <ul>
        <xsl:apply-templates select="ncx:navPoint"/>
      </ul>
    </xsl:if>
  </li>
</xsl:template>

</xsl:stylesheet>

This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>