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 May 13th, 2010, 04:48 PM
Registered User
 
Join Date: May 2010
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default 'email a friend' link in xslt

I thought I was pretty close to getting this to work, but I could be way off. The system I'm using stores a variable called 'title' that keeps the title of an article stored. It also has 'url' which, as you guessed, keeps the URL of the article stored. I'd like to call both of these inside this snippet below to 'email a friend.'

The problem is, that snippet doesn't like the < and > signs. How else can I can I call that variable? I want the title of the article to be passed to the subject line. Once I get that, I'll figure out how to pass the URL variable to the body of the email.

Code:
            <div class="title">
              <a href="mailto:&amp;subject=<xsl:value-of select='title'/>&amp;body=<xsl:value-of select='url'/>">Email a Friend</a>
            </div>
 
Old May 14th, 2010, 03:09 AM
Friend of Wrox
 
Join Date: Jun 2008
Posts: 291
Thanks: 9
Thanked 29 Times in 29 Posts
Thumbs up

Change <xsl:value-of select='title'/> and <xsl:value-of select='url'/> with {title} and {url}
__________________
Rummy

Last edited by mrame; May 14th, 2010 at 03:13 AM..
 
Old May 14th, 2010, 01:33 PM
Friend of Wrox
 
Join Date: Jul 2006
Posts: 430
Thanks: 28
Thanked 5 Times in 5 Posts
Send a message via Yahoo to bonekrusher
Default

Additional Info:

They are called Attribute Value Templates.

see http://www.w3.org/TR/xslt20/#attribute-value-templates
 
Old May 17th, 2010, 11:26 AM
Registered User
 
Join Date: May 2010
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

The problem is, I cannot input the title and url for each article. They are being generated from an XSL loop above in the code from a SQL database.
 
Old May 17th, 2010, 11:29 AM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

No, we mean 'literally', replace the <xsl:value-of> bit with {elementname}.

Like this:

Code:
<div class="title">
              <a href="mailto:&amp;subject={title}&amp;body={url}">Email a Friend</a>
            </div>
If that doesn't work then perhaps showing us a bit more of your code and some of your input XML might help.
__________________
/- Sam Judson : Wrox Technical Editor -/

Think before you post: What have you tried?
 
Old May 17th, 2010, 11:46 AM
Registered User
 
Join Date: May 2010
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Does not work. I get an error:

msgtype:error
code:2
module:Sablotron
URI:arg:/xsl
line:55
msg:XML parser error 4: not well-formed (invalid token)

This is the entire code:

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

<xsl:template match="/feeds">
<html>
  <head>
    <style>
      body     { color: #000000; background-color: #ffffff; }
      H2 {font-size: 13pt; font-family: Arial;}
      a:link   {color: #006c43}
      a:visited{color: #006c43;}
      a:hover  {color: gray;}
      .date  {font-size: 9pt; font-family: Arial;}
      .source  {font-size: 9pt; font-family: Arial;}
      .title  {font-size: 10pt; font-family: Arial; color: #006c43; text-decoration: underline;}
      .ingress {font-size: 10pt; font-style: italic; font-family: Times;}
      .match {font-size: 10pt; font-style: italic; font-family: Verdana, arial, sans-serif;}
      .title a:link {font-size: 10pt; font-family: Arial; color: #006c43; text-decoration: underline;}
      .title a:visited{color: #006c43;}
      .title a:hover  {color: gray;}
    </style>
  </head>
  <body>
    <xsl:apply-templates/>
  </body>
</html>
</xsl:template>

<xsl:template match="feed">
  <h2><xsl:value-of select="name"/></h2>
  <table border="0">
    <xsl:for-each select="documents/document">
      <xsl:if test="(alike&lt;2 or docId=alike)">
        <tr>
          <td nowrap="" valign="top">
            <span class="date"><xsl:value-of select="createDate2"/>,</span> <span class="source"><xsl:value-of select="sourcename"/></span>
            <br/>
            <div class="title">
              <a>
                <xsl:attribute name="href"><xsl:value-of select="url"/></xsl:attribute>
                <xsl:attribute name="target">_blank</xsl:attribute>
                <xsl:value-of select="title2"/>
              </a>
            </div>
          </td>
        </tr>
        <tr>
          <td>
            <span class="ingress"><xsl:value-of select="ingress"/></span>
          </td>
        </tr>
        <tr>
          <td>
            <a href="mailto:&subject={title}&body={url}">Email a Friend</a>
          </td>
        </tr>
        <tr><td></td></tr>
      </xsl:if>
    </xsl:for-each>
  </table>
</xsl:template>

</xsl:stylesheet>
The code takes articles from a database and outputs them into a webpage. I would like to add a line underneath the ingress (short description of article) that enables any user to email that particular article to a friend, and include the article title as the subject line, and the url in the body of the email.
 
Old May 17th, 2010, 11:50 AM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

OK, that error means that the document is not valid XML - this is because you need to encode the & symbol and replace it with "&amp;".
__________________
/- Sam Judson : Wrox Technical Editor -/

Think before you post: What have you tried?
 
Old May 17th, 2010, 12:17 PM
Registered User
 
Join Date: May 2010
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

It worked!!!

This is great news! Thanks so much for your help!





Similar Threads
Thread Thread Starter Forum Replies Last Post
How to give Email link apurva BOOK: Beginning ASP.NET 2.0 and Databases 1 March 26th, 2009 06:14 AM
how to email some page to the friend sandeepgreaternoida ASP.NET 2.0 Basics 2 January 2nd, 2009 12:04 PM
Gridview Email Link ronhawker General .NET 0 November 9th, 2006 07:12 PM
Making an email address link jks709 Classic ASP Databases 1 July 28th, 2004 01:14 PM





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