Re: [xsl] XHTML table of contents with XSLT

Subject: Re: [xsl] XHTML table of contents with XSLT
From: Martin Honnen <Martin.Honnen@xxxxxx>
Date: Sat, 24 Feb 2007 17:46:34 +0100
Daniel K. Schneider wrote:

(2) David Carlisle told me to replace the ugly "*[local-name()='xxx']" by "h:xxx"
but then I run into namespace problems (this why I put them there in the first place).

I think your stylesheet is supposed to generate XHTML output with result elements in the XHTML namespace so the stylesheet should have the XHTML namespace as the default namespace (at least for the easiest way to make sure all result elements are in that namespace). Then for XPath expressions and match patterns to be able to select/match elements in the XHTML namespace you need a declaration binding a prefix to the namespace too. To avoid that the prefix is later appearing in the output and making the markup invalid in terms of (rather limited) DTD validation use exclude-result-prefixes e.g.


Then you can use e.g.

<xsl:template match="/h:html">
      <title><xsl:value-of select="h:title"/></title>

    <body bgcolor="#FFFFFF">
      <xsl:apply-templates select="h:body"/>

<xsl:template match="h:body">
  <strong><a name="toc">Contents</a></strong>
  <xsl:apply-templates select="h:h1 | h:h2" mode="toc"/>
  <xsl:apply-templates />


<xsl:template match="h:h1" mode="toc">
  <a href="#h1_{generate-id(.)}"><xsl:value-of select="."/></a><br/>

and so on.


	Martin Honnen

Current Thread