O'Reilly logo

XSLT Cookbook by Sal Mangano

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Creating Hyperlinked Documents

Problem

You want to convert XML into hyperlinked HTML content.

Solution

A typical course of action when converting XML into HTML is to make two or more passes over the XML to create menu or index pages and content pages. The menu pages contain links to the content pages. The following solution generates an index and summary pages for SalesBySalesPerson.xml (see Chapter 2):

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:saxon="http://icl.com/saxon" extension-element-prefixes="saxon"> <xsl:output method="html"/> <xsl:template match="/"> <xsl:apply-templates select="*" mode="index"/> <xsl:apply-templates select="*" mode="content"/> </xsl:template> <!-- = = = = = = = = = = = = = = = = = = = = = = = = = = --> <!-- Create index.html (mode = "index") --> <!-- = = = = = = = = = = = = = = = = = = = = = = = = = = --> <xsl:template match="salesBySalesperson" mode="index"> <saxon:output href="index.html"> <html> <head> <title>Sales By Salesperson Index</title> </head> <body bgcolor="#FFFFFF" text="#000000"> <h1>Sales By Salesperson</h1> <xsl:apply-templates mode="index"/> </body> </html> </saxon:output> </xsl:template> <xsl:template match="salesperson" mode="index"> <h2> <a href="{concat(@name,'.html')}"> <xsl:value-of select="@name"/> </a> </h2> </xsl:template> <!-- = = = = = = = = = = = = = = = = = = = = = = = = = = --> <!-- Create @name.html (mode = "content") --> <!-- = = = = = = = = = = = = = = = = = = = = = = = = = ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required