[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: Producing a Table of Contents

Subject: RE: Producing a Table of Contents
From: "Andrew Welch" <AWelch@xxxxxxxxxxxxxxx>
Date: Fri, 26 Mar 2004 10:57:30 -0000
h1 table of contents
> When doing a transformation, is there any 'clever' way of 
> generating a 
> table of contents in the XSLT based on the actual content of the 
> template?
> 
> For example, the template has lots of sections of text preceded with 
> headings (using <h1></h1> tags).  Using XSLT is it possible to search 
> through the template to draw up a list of the text between these tags?

You can use the fact that calling document('') with no parameter will
return the stylesheet, so you can then iterate through the templates
extracting the elements you need.

This stylesheet:

<xsl:stylesheet version="1.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="/">
  <xsl:for-each select="document('')/*/xsl:template/h1">
    <xsl:element name="{local-name()}">
      <xsl:value-of select="."/>
    </xsl:element>
  </xsl:for-each>
</xsl:template>

<xsl:template match="one">
  <h1>heading one</h1>
</xsl:template>

<xsl:template match="two">
  <h1>heading two</h1>
</xsl:template>

</xsl:stylesheet>

When applied to itself, produces:

<h1>heading one</h1><h1>heading two</h1>

cheers
andrew

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.