HTTP links in xml file being displayed in XSLT


R

requeth

I have the following XML file:

<?xml version="1.0" encoding="ISO-8859-1"?>
<?xml-stylesheet type="text/xsl" href="table_classname.xsl"?>
<root>
<classinfo>
<classname>Rhetoric 10</classname>
<classlink>http://webcast.berkeley.edu/course_details.php?
seriesid=1906978535</classlink>
<classrating>"A"</classrating>
<university>"UC Berkeley"</university>
</classinfo>
<classinfo>
<classname>"Physics 10"</classname>
<classlink>http://webcast.berkeley.edu/course_details.php?
seriesid=1906978535</classlink>
<classrating>"A+"</classrating>
<university>"UC Berkeley+"</university>
</classinfo>
</root>

And the following XSLT file:

<?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>
<table border="1">
<tr bgcolor="#9acd32">
<th align="left">Class</th>
<th align="left">University</th>
<th align="left">Rating</th>
</tr>
<xsl:for-each select="root/classinfo">
<xsl:sort select="classname"/>
<tr>
<td>
<a><a href="<xsl:value-of select="classlink"/>"><xsl:value-of
select="classname"/></a>
</td>
<td><xsl:value-of select="university"/></td>
<td><xsl:value-of select="classrating"/></td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>

I'm trying to get the href link section to pull the classlink
attribute out and the classname attribute out and render it as an HTTP
link. This is throwing an error stating I cant have < in an attribute.
Anyone know how I can get the link to render properly?
 
Ad

Advertisements

J

Johannes Koch

<a><a href="<xsl:value-of select="classlink"/>"><xsl:value-of
select="classname"/></a> [...]
I'm trying to get the href link section to pull the classlink
attribute out and the classname attribute out and render it as an HTTP
link. This is throwing an error stating I cant have < in an attribute.

XSLT itself uses XML syntax. So you can't just put tags wherever you
like, and hope that it works.
Anyone know how I can get the link to render properly?

Use xsl:attribute or attribute value templates. See the XSLT spec or a
good tutorial for the use of these.
 
Ad

Advertisements

M

Martin Honnen

<a><a href="<xsl:value-of select="classlink"/>"><xsl:value-of
select="classname"/></a>

Use an attribute value template
<a href="{classlink}">
<xsl:value-of select="classname"/>
</a>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top