XML Editor
Sign up for a WebBoard account Sign Up Keyword Search Search More Options... Options
Chat Rooms Chat Help Help News News Log in to WebBoard Log in Not Logged in
Show tree view Topic
Topic Page 1 2 3 4 5 6 7 8 9 Go to previous topicPrev TopicGo to next topicNext Topic
Postnext
bb saidSubject: a href in a xml to xslt transform
Author: bb said
Date: 01 Apr 2005 03:45 AM
I have an xml file that is converted to html with xslt.

What I am trying to figure out is how to include a url in the xml file and have it transformed into an html a href link

For example the xml would be

<links>
<link>http://www.yahoo.com</link>
</links>

And the resulting html after xslt transform would be

<a href=http://www.yahoo.com>Yahoo!</a>

This would also mean having the linked text (Yahoo!) defined somewhere in the xml file

Postnext
(Deleted User) Subject: a href in a xml to xslt transform
Author: (Deleted User)
Date: 01 Apr 2005 09:50 AM
Hi Said,

>[..] For example the xml would be
>
><links>
><link>http://www.yahoo.com</link>
></links>
>

You don't specify how you reach that link, so I am assuming you just
want to convert a list of URL into an HTML with the corresponding
clickable links.
In this case, this stylesheet should do the work:

<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html"/>
<xsl:template match="/">
<html>
<body>
<xsl:apply-templates/>
</body>
</html>
</xsl:template>

<xsl:template match="link">
<a href="{text()}">
<xsl:value-of select="@text"/>
</a>
</xsl:template>
</xsl:stylesheet>

Hope this helps,
Alberto

Postnext
bb saidSubject: a href in a xml to xslt transform
Author: bb said
Date: 01 Apr 2005 12:08 PM
Thank you Alberto,

I'm pretty new to xml (just started using XML this week) and I was wondering if you could show me exactly how both the xml and xslt should look to make this work.

Also I'm not sure what "{text()}" refers to.

What the ultimate output is supposed to be is an HTML table with 5 <td></td> using for-each in xslt. The first 4 td's only contain text but the last one will contain several links to files. Here is the actual xml and xslt I will be using:

XML: (transform.xml)

<?xml version="1.0" encoding="iso-8859-1"?>
<?xml-stylesheet href="transform.xsl" type="text/xsl"?>

<opportunity>
<category>text</category>
<program>text</program>
<description>text</description>
<funder>text</funder>
<duedate>text</duedate>
<furtherinfo>multiple URL's defined here or somewhere in the XML</furtherinfo>
</opportunity>



XSLT: (transform.xsl)

<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<body>
<h2>Funding Opportunities</h2>
<table border="1">
<tr bgcolor="#9acd32">
<th>Program</th>
<th>Description</th>
<th>Funder</th>
<th>Due Date</th>
<th>Further Info</th>
</tr>
<xsl:for-each select="allopportunities/opportunity">
<tr>
<td><xsl:value-of select="program"/></td>
<td><xsl:value-of select="description"/></td>
<td><xsl:value-of select="funder"/></td>
<td><xsl:value-of select="duedate"/></td>
<td><xsl:value-of select="furtherinfo"/>links to files go here</td>
</tr>
</xsl:for-each>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>

This example transforms just fine but I still can't figure out how to get the links in there.

Thanks for your help.

Posttop
bb saidSubject: a href in a xml to xslt transform
Author: bb said
Date: 01 Apr 2005 12:11 PM
in my example I closed </xsl:for-each> twice, that's a typo.

 
Topic Page 1 2 3 4 5 6 7 8 9 Go to previous topicPrev TopicGo to next topicNext Topic
Download A Free Trial of Stylus Studio 6 XML Professional Edition Today! Powered by Stylus Studio, the world's leading XML IDE for XML, XSLT, XQuery, XML Schema, DTD, XPath, WSDL, XHTML, SQL/XML, and XML Mapping!  
go

Log In Options

Site Map | Privacy Policy | Terms of Use | Trademarks
Stylus Scoop XML Newsletter:
W3C Member
Stylus Studio® and DataDirect XQuery ™are from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2016 All Rights Reserved.