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

RE: How to add a variable/changeable hyperlink <a href=" htt

Subject: RE: How to add a variable/changeable hyperlink <a href=" http:\\WWW....> around a text in XSL?
From: "John E. Simpson" <simpson@xxxxxxxxxxx>
Date: Mon, 15 Mar 1999 22:54:19 -0500
html href variable
At 02:19 PM 3/15/99 -0800, Koh, Justin (Intern) wrote:
>Well let's say that the XML document is something like this
>
><profile number="1">
>	<data>.....</data>
>	<filename>datacycle.html</filename>
></profile>
>
><profile number="2">
>	<data>.....</data>
>	<filename>dataframe.html</filename>
></profile>

I added a <doc> container element, so the XML looks like this:

	<doc>
	   <profile number="1">
	      <data>blahblah1</data>
	      <filename>datacycle.html</filename>
	   </profile>
	   <profile number="2">
	      <data>blahblah2</data>
	      <filename>dataframe.html</filename>
	   </profile>
	</doc>

(You'd replace the <doc>s with whatever your own containing parent element
might be.)

Then I used this XSL:

	<xsl:stylesheet
   	   xmlns:xsl="http://www.w3.org/TR/WD-xsl"
         xmlns="http://www.w3.org/TR/REC-html40"
         result-ns="">
	   <xsl:template match="doc">
		<html><body><ul>
		   <xsl:for-each select="profile">
			<li>Profile #<xsl:value-of select="@number"/>
			<br/>
			Data: <xsl:value-of select="data"/>
			<br/>
			Filename: <a href="{filename}"><xsl:value-of select="filename"/></a>
			</li>
		   </xsl:for-each>
		</ul>
		</body></html>
	   </xsl:template>
	</xsl:stylesheet>

The operative portion of that is the line beginning "Filename:"; it plugs
the value of the filename element into both the href attribute AND the
content of the <a> tag.  (Note that the occurrence of filename in the href
attribute is set off by curly braces, not simple parens.) I ran it through
XT-win using this command line:
	xt testurl.xml testurl.xsl testurl.html

The HTML generated is:

	<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
	<html>
	<body>
	<ul>
	<li>Profile #1<br>
          Data: blahblah1<br>
          Filename: <a href="datacycle.html">datacycle.html</a>
	</li>
	<li>Profile #2<br>
          Data: blahblah2<br>
          Filename: <a href="dataframe.html">dataframe.html</a>
	</li>
	</ul>
	</body>
	</html>

Which displays like this:

	o Profile #1
        Data: blahblah1
        Filename: datacycle.html 
      o Profile #2
        Data: blahblah2
        Filename: dataframe.html 

(substituting lowercase "o" chars for the bullets that actually appear).
Both "datacycle.html" and "dataframe.html" appear as highlighted hyperlinks.

I imagine the same would work with IE5, as long as you include the doctype
declaration and so on in the document. The important thing though is that
you can get the filename to appear both as the value of an href= attribute
and as the content of the <a> element.

Btw, if you need to prefix the filename with a protocol, server, etc., make
the XSL look like this:

	<a href="http://server/path/{filename}"><xsl:value-of select="filename"/></a>

==========================================================
John E. Simpson            | The secret of eternal youth
simpson@xxxxxxxxxxx        | is arrested development.
http://www.flixml.org      |  -- Alice Roosevelt Longworth


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


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.