PDA

View Full Version : creating a hyperlink in XSL


The Reverend
07-15-2006, 12:06 AM
I'm new to XML and XSL, I've been doing this about 24 hours so far.

I'm making an XSL template to organize a listing type directory.

<item>
<name>John</name>
<email>john@example.com</email>
<website>example.com</website>
<phone contactname="James">408-555-5555</phone>
</item>

I'm trying to take the website in the template and change it into a url. But doing it like this

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

produces an error.

What is the proper way to do this?

second question:

How do I include html entities? &nbsp; produces an error message.

macchisp
07-17-2006, 02:04 PM
To create a hyperlink, you would use the following format:

<xsl:attribute name="href"><xsl:value-of select="website" /></xsl:attribute><xsl:value-of select="website" /></a>


XSL using a different character encoding so you should use instead of &nbsp;.

macchisp
07-17-2006, 02:05 PM
I'm sorry, I forgot to put a opening <a> tag, so use the following:
<a><xsl:attribute name="href"><xsl:attribute name="href"><xsl:value-of select="website" /></xsl:attribute><xsl:value-of select="website" /></a>

The Reverend
07-18-2006, 01:38 AM
To create a hyperlink, you would use the following format:

<xsl:attribute name="href"><xsl:value-of select="website" /></xsl:attribute><xsl:value-of select="website" /></a>


XSL using a different character encoding so you should use instead of &nbsp;.
Thanks, that worked perfect, what should I use instead of &nbsp; though?

macchisp
07-18-2006, 03:50 PM
It rendered it as a space when I typed it before but here it is: & #160;

There should not be a space between the & and #.

probey20
08-14-2006, 09:22 PM
Another way to write out an href tag:

<a href="{website}"><xsl:value-of select="website"/></a>

Another way to write out a non-breaking space:

<xsl:text disable-output-escaping="yes"><![CDATA[&nbsp;]]></xsl:text>