[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

Re: [xsl] Dynamically Creating HTML Links, actual snippet


Subject: Re: [xsl] Dynamically Creating HTML Links, actual snippet
From: Wendell Piez <wapiez@xxxxxxxxxxxxxxxx>
Date: Thu, 30 Nov 2006 11:58:41 -0500

Hi,

At 11:11 AM 11/30/2006, you wrote:
<?xml version="1.0" encoding="ISO_8859-1"?>

<show>

<slide>
        <heading>Dog hobbies</heading>
        <contents>The dog likes to watch
television.</contents>
</slide>

<slide>
        <heading>Dog food</heading>
        <contents>The dog likes to eat
Kenlration.</contents>
</slide>

<slide>
        <heading>Dog sleeping</heading>
        <contents>The dog likes to sleep on the
bed.</contents>
</slide>

</show>

and the following. . .

<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
    <xsl:output method="html" encoding="ISO_8859-1"/>
    <!-- DEFINE THE DOCUMENT LEVEL TEMPLATE -->
    <xsl:include href="basichtmlformatting.xsl"/>
    <xsl:template match="slide">
        <div class="about">
            <xsl:apply-templates/>

<!-- what do I do here to create an html link from
each slide to the next slide? something of the format
"slide01.html" -->

<xsl:variable name="next-slide-filename"> <xsl:apply-templates select="following-sibling::slide" mode="filename"/> </xsl:variable>

<div class="navbar">
  <a href="{$next-slide-filename}">Next</a>
</div>

...
</xsl:template>

and (elsewhere in your stylesheet)

<xsl:template match="slide" mode="filename"/>
  <xsl:text>slide</xsl:text>
  <xsl:number format="01"/>
  <xsl:text>.html</xsl:text>
</xsl:template>

... which is a general purpose template you can use for any slide to get its name (so also useful for the previous and first slides, etc.).

The 'next-slide-filename' variable will come out empty when there is no next slide. This is easy to test.

Cheers,
Wendell



======================================================================
Wendell Piez                            mailto:wapiez@xxxxxxxxxxxxxxxx
Mulberry Technologies, Inc.                http://www.mulberrytech.com
17 West Jefferson Street                    Direct Phone: 301/315-9635
Suite 207                                          Phone: 301/315-9631
Rockville, MD  20850                                 Fax: 301/315-8285
----------------------------------------------------------------------
  Mulberry Technologies: A Consultancy Specializing in SGML and XML
======================================================================


Current Thread
Keywords
xml