forrest-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Robert Koberg" <...@koberg.com>
Subject RE: suggestion for dtd
Date Wed, 06 Nov 2002 14:51:09 GMT
Hi guys,

If the anchor is on the same page (for something like a table of contents) you
don't need to put IDs in your elements. You could use the xsl function
generate-id(). This function is guaranteed to return the same value for a node
whenever it is called in the XSL transformation. Using this technique you do not
have to worry about maintaining the ID's. For example you have some templates
that create a TOC:

<?xml version="1.0" encoding="iso-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template name="toc">
  <div class="toctitle">
    Page Table of Contents:
  </div>
  <div class="toc">
    <xsl:apply-templates select="$page_nodeset/col[@type='wide_center']"
mode="start_toc"/>
  </div>
</xsl:template>

<xsl:template match="article" mode="toc">
  <xsl:apply-templates select="h | h1 | h2 | h3 | h4 | h5 | section"
mode="toc"/>
</xsl:template>

<xsl:template match="section" mode="toc">
  <div class="tocsection">
    <xsl:apply-templates select="h | h1 | h2 | h3 | h4 | h5 | section"
mode="toc"/>
   </div>
</xsl:template>

<xsl:template match="h | h1 | h2 | h3 | h4 | h5" mode="toc">
  <div class="tocitem">
    <a href="#{generate-id()}">
      <xsl:value-of select="."/>
    </a>
    <xsl:apply-templates select="h | h1 | h2 | h3 | h4 | h5 | section"
mode="toc"/>
  </div>
</xsl:template>
</xsl:stylesheet>

Then in some template that styles the content you would have:

<xsl:template match="h | h1 | h2 | h3 | h4 | h5">
  <xsl:copy>
    <xsl:copy-of select="@*"/>
    <xsl:attribute name="id">
      <xsl:value-of select="generate-id()"/>
    </xsl:attribute>
    <xsl:apply-templates/>
  </xsl:copy>
</xsl:template>

best,
-Rob


> -----Original Message-----
> From: Jeff Turner [mailto:jefft@apache.org]
> Sent: Wednesday, November 06, 2002 6:39 AM
> To: forrest-dev@xml.apache.org
> Subject: Re: suggestion for dtd
>
>
> On Wed, Nov 06, 2002 at 08:34:33AM -0500, Rodent of Unusual Size wrote:
> > i would like to suggest that the 'title' element allow an 'anchor'
> > within it, and/or that 'section' allow 'anchor' before 'title'.
>
> Try using the 'id' attribute on the section:
>
> <section id="doing_stuff">
>   <title>Doing Stuff</title>
>   ...
>
>
> <p>.. in the <link href="#doing_stuff">Doing Stuff</link> section.
>
> --Jeff
>
> > otherwise, the archor ends up being *after* the section title, and
> > someone following a link to it will arrive at a screen view whose
> > title is just off the top of the screen.
>



Mime
View raw message