Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 1st, 2007, 08:21 AM
Registered User
 
Join Date: Dec 2007
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default "Back to top" link using template names

Hello,
At the end of my html page I want to add the hyperlink "back to the top" that points to the top of the page.
I want to do this using the xsl:call-template element.

I guess i have to use sth like that in my stylesheet :

<xsl:template match="/">
        <xsl:call-template name="top"/>
        <xsl:apply-templates/>
        <xsl:call-template name="bottom"/>
  </xsl:template>

  <xsl:template name="bottom">
    <xsl:text>This is the bottom of the page</xsl:text>
  </xsl:template>

  <xsl:template name="top">
    <xsl:text>This is the top of the page</xsl:text>
  </xsl:template>

But how do I integrate the hyperlink, and where do I put it in the stylesheet? Has anyone a complete xsl stylesheet example with that?

 
Old December 1st, 2007, 08:51 AM
Friend of Wrox
 
Join Date: Nov 2007
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
Default

If you want to generate a HTML document with your XSLT stylesheet then you should make sure you have the proper HTML document structure with a html root element containing a head and a body element:

Code:
<xsl:template match="/">
  <html lang="en">
    <head>
      <title>document title</title>
    </head>
    <body>
      <xsl:call-template name="top"/>
      <xsl:apply-templates/>
      <xsl:call-template name="bottom"/>
    </body>
  </html>
</xsl:template>

<xsl:template name="top">
<div id="t">This is the top of the page.</div>
</xsl:template>

<xsl:template name="bottom">
  <a href="#t">go to top</a>
</xsl:template>
 
Old December 1st, 2007, 09:22 AM
Registered User
 
Join Date: Dec 2007
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
quote:Originally posted by Martin Honnen
 If you want to generate a HTML document with your XSLT stylesheet then you should make sure you have the proper HTML document structure with a html root element containing a head and a body element:

Code:
<xsl:template match="/">
  <html lang="en">
    <head>
      <title>document title</title>
    </head>
    <body>
      <xsl:call-template name="top"/>
      <xsl:apply-templates/>
      <xsl:call-template name="bottom"/>
    </body>
  </html>
</xsl:template>

<xsl:template name="top">
<div id="t">This is the top of the page.</div>
</xsl:template>

<xsl:template name="bottom">
  <a href="#t">go to top</a>
</xsl:template>
Thank you.
But at which places exactly do I integrate this code into my stylesheet?
I want the "back to top" link to point to the title: <title>Outils XML</title>


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

<xsl:output method="html"
encoding="utf-8"/>


<xsl:template match="/">


<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>Outils XML</title>
</head>

<body>

<h2>Outils XML</h2>
    <table border="1">
    <tr>
        <th>Nom</th>
        <th>Auteurs</th>
        <th>Licence</th>
        <th>Téléchargement</th>
        <th>Commentaire</th>
    </tr>
    <xsl:for-each select="ListeOutils/outil">

<tr>
    <td><xsl:value-of select="nom"/></td>
    <td><xsl:value-of select="auteurs"/></td>
    <td><xsl:value-of select="licence"/></td>
    <td><xsl:value-of select="téléchargement"/></td>
    <td><xsl:value-of select="commentaire"/></td>
</tr>

     </xsl:for-each>
</table>


</body>
</html>


</xsl:template>

</xsl:stylesheet>


 
Old December 1st, 2007, 09:59 AM
Friend of Wrox
 
Join Date: Nov 2007
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
Default

In my view a link to the title element does not make sense as the title is not rendered as part of the document. You need to link to an element inside of the body section of the HTML document. So you could link to that h2 element by giving it an id attribute value:

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

<xsl:output method="html"
encoding="utf-8"/>


<xsl:template match="/">


<html lang="fr">
<head>
<title>Outils XML</title>
</head>

<body>

<h2 id="t">Outils XML</h2>
    <table border="1">
    <tr>
        <th>Nom</th>
        <th>Auteurs</th>
        <th>Licence</th>
        <th>Téléchargement</th>
        <th>Commentaire</th>
    </tr>
    <xsl:for-each select="ListeOutils/outil">

<tr>
    <td><xsl:value-of select="nom"/></td>
    <td><xsl:value-of select="auteurs"/></td>
    <td><xsl:value-of select="licence"/></td>
    <td><xsl:value-of select="téléchargement"/></td>
    <td><xsl:value-of select="commentaire"/></td>    
</tr>    

     </xsl:for-each>  
</table>

<xsl:call-template name="bottom"/>
</body>
</html>
 
</xsl:template>

<xsl:template name="bottom">
  <a href="#t">go to top</a>
</xsl:template>

</xsl:stylesheet>
 
Old December 1st, 2007, 10:30 AM
Registered User
 
Join Date: Dec 2007
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
quote:Originally posted by Martin Honnen
 In my view a link to the title element does not make sense as the title is not rendered as part of the document. You need to link to an element inside of the body section of the HTML document. So you could link to that h2 element by giving it an id attribute value:

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

<xsl:output method="html"
encoding="utf-8"/>


<xsl:template match="/">


<html lang="fr">
<head>
<title>Outils XML</title>
</head>

<body>

<h2 id="t">Outils XML</h2>
    <table border="1">
    <tr>
        <th>Nom</th>
        <th>Auteurs</th>
        <th>Licence</th>
        <th>Téléchargement</th>
        <th>Commentaire</th>
    </tr>
    <xsl:for-each select="ListeOutils/outil">

<tr>
    <td><xsl:value-of select="nom"/></td>
    <td><xsl:value-of select="auteurs"/></td>
    <td><xsl:value-of select="licence"/></td>
    <td><xsl:value-of select="téléchargement"/></td>
    <td><xsl:value-of select="commentaire"/></td>    
</tr>    

     </xsl:for-each>  
</table>

<xsl:call-template name="bottom"/>
</body>
</html>
 
</xsl:template>

<xsl:template name="bottom">
  <a href="#t">go to top</a>
</xsl:template>

</xsl:stylesheet>

Thank you so much!!






Similar Threads
Thread Thread Starter Forum Replies Last Post
calling one template in other template VijayKumar XSLT 3 September 15th, 2005 11:12 AM
SELECT TOP n NOT SELECTING TOP n! ibi SQL Language 8 March 30th, 2005 08:08 PM
history.back or hitting the back button won't work lian_a Classic ASP Basics 4 July 29th, 2004 12:14 AM
Need help with TOP 5 and self join funkedup SQL Language 2 May 17th, 2004 11:36 AM
SELECT TOP !!!! Jane SQL Language 2 October 17th, 2003 11:22 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.