By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,678 Members | 1,158 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,678 IT Pros & Developers. It's quick & easy.

Need help with XLink and XSL documents

P: 1
I have an XML and XSL document. I am trying to incorporate hyperlinks throughout the XML document. I have read many of the related posts on this and other forums but I can't seem to get it right. Please help! Do I have to declare the namespace in the XSL doc also as shown below or should I take it out? No matter what I do, nothing appears for the link tag in the browser.

a piece of my xml DOC (using google for now as an easy example but google will not be my actual webpage):

[html]<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="genre.xsl"?>

<movielist>
<intro>Browse the Foreign Movies</intro>

<movie language="spanish" country="mexico" genre="drama">
<title>Y Tu Mamá También</title>
<date>2002</date>
<country>Mexico</country>
<language>Spanish</language>
<rating>R</rating>
<director>Alfonso Cuarón</director>
<actors>Ana López Mercado, Gael García Bernal, Diego Luna</actors>
<genre>Drama</genre>
<summary>In Mexico, two teenage boys and an attractive older woman embark on a road trip and learn a thing or
two about life, friendship, and each other.</summary>
<link> xmlns:xlink="http://www.w3.org/1999/xlink/"
xlink:type="simple" xlink:href="http://www.google.com"
xlink:title="Google" xlink:role=""http://www.w3.org/1999/XSL/Transform">
xlink:actuate="onRequest"
</link>
</movie>[/html]


xsl document in whole:
[html]<?xml version="1.0" encoding="ISO-8859-1" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xlink="http://www.w3.org/1999/xlink" exclude-result-prefixes="xlink">


<xsl:key name="genre" match="movie" use="@genre" />
<xsl:template match="/movielist">
<html>
<head>
<title>Movies By Genre</title>
</head>
<body>
<H1><xsl:apply-templates select="intro"/></H1>
<H1>By Genre</H1>

<a href="genre.xml#t1">Action</a>
<br></br>
<a href="genre.xml#t2">Animation</a>
<br></br>
<a href="genre.xml#t3">Comedy</a>
<br></br>
<a href="genre.xml#t4">Drama</a>
<br></br>
<a href="genre.xml#t5">Suspense</a>

<a name="t1"><H1>Action Movies</H1></a>
<xsl:apply-templates select="key('genre', 'action')">
<xsl:sort select="title"/>
</xsl:apply-templates>

<a name="t2"><H1>Animation Movies</H1></a>
<xsl:apply-templates select="key('genre', 'animation')">
<xsl:sort select="title"/>
</xsl:apply-templates>

<a name="t3"><H1>Comedy Movies</H1></a>
<xsl:apply-templates select="key('genre', 'comedy')">
<xsl:sort select="title"/>
</xsl:apply-templates>

<a name="t4"><H1>Drama Movies</H1></a>
<xsl:apply-templates select="key('genre', 'drama')">
<xsl:sort select="title"/>
</xsl:apply-templates>

<a name="t5"><H1>Suspense Movies</H1></a>
<xsl:apply-templates select="key('genre', 'suspense')">
<xsl:sort select="title"/>
</xsl:apply-templates>
</body>
</html>
</xsl:template>

<xsl:template match="movie">
<table>
<tr>
<td colspan="2"><h2><b><xsl:value-of select="title" /></b></h2></td>
</tr>
<tr>
<td><b>Date: </b></td> <td><xsl:value-of select="date" /></td>
</tr>
<tr>
<td><b>Country: </b></td> <td><xsl:value-of select="country" /></td>
</tr>
<tr>
<td><b>Language: </b></td> <td><xsl:value-of select="language" /></td>
</tr>
<tr>
<td><b>Rating: </b></td> <td><xsl:value-of select="rating" /></td>
</tr>
<tr>
<td><b>Director: </b></td> <td><xsl:value-of select="director" /></td>
</tr>
<tr>
<td><b>Actors: </b></td> <td><xsl:value-of select="actors" /></td>
</tr>
<tr>
<td><b>Genre: </b></td> <td><xsl:value-of select="genre" /></td>
</tr>
<tr>
<td valign="top"><b>Summary: </b></td> <td><xsl:value-of select="summary" /></td>
</tr>
</table>
<br></br>
</xsl:template>

<xsl:template match="link">
<link href="{@xlink:href}">
<xsl:apply-templates>
</link>
</xsl:template>




</xsl:stylesheet>[/html]
May 2 '07 #1
Share this Question
Share on Google+
1 Reply


dorinbogdan
Expert 100+
P: 839
Welcome to TheScripts TSDN....

The HTML hyperlink tag is <a>, so use:
[html]<a href="{@xlink:href}">
<xsl:apply-templates>
</a>[/html]
May 2 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.