Welcome to WebmasterWorld Guest from 54.159.44.227

Forum Moderators: httpwebwitch

Message Too Old, No Replies

Transforming URL in XML data to hyperlink with XSL

     

mcfly

3:12 pm on Dec 1, 2004 (gmt 0)

10+ Year Member



Hi all,

I am using an XML document as a source of a list of URLs and their descriptions and wish to transform these to a series of hyperlinks using XSL along the lines of that below.

In XML Doc:
<urls>
<url desc="A description" address="www.widget.com" />
<url desc="Blah" address="www.bluewidgets.com" />
</urls>

In XSL Doc:
<xsl:for-each select="urls/url">
<br/>
<a href=" <xsl:value-of select="@address" /> ">
<xsl:value-of select="@desc" />
</a>
</xsl:for-each>

Obviously the above XSL is not valid, but I don't know how to insert the URL into the href value. Any ideas how to get around this? It seems such a simple thing to want to do, but is proving problematic!

Thanks in advance.

Alternative Future

3:22 pm on Dec 1, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi mcfly,

If your using FOP then this is the code:

<fo:basic-link external-destination="{url}">
<xsl:value-of select="title"/>
</fo:basic-link>

or

<a href="{@address}"> in the context you are using

-George

mcfly

3:42 pm on Dec 1, 2004 (gmt 0)

10+ Year Member



Thanks for your suggestion Alternative Future.

I'm not familar with FOP but will look into it. I take it this can be used with ASP/IIS?

Alternative Future

3:51 pm on Dec 1, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If you are printing out in PDF format then it would be worth looking into otherwise it might be best sticking with the xsl suggestion which should work.

-george

mcfly

4:01 pm on Dec 1, 2004 (gmt 0)

10+ Year Member



Cheers George, the simple <a href="{@url}"> does the job nicely.

syber

1:58 pm on Dec 7, 2004 (gmt 0)

10+ Year Member



The solution is to use xsl element and attribute tags:

<xsl:for-each select="urls/url">
<br/>
<xsl:element name="a">
<xsl:attribute name="href">
<xsl:value-of select="@address" />
</xsl:attribute>
<xsl:value-of select="@desc" />
</xsl:element>
</xsl:for-each>

Art

ArcoJedi

9:50 pm on Dec 14, 2004 (gmt 0)

10+ Year Member



Is it possible to turn an XML element image path into an HTML image tag with XSL? If you can create a link (href), I'd bet you could do an image tag (img src), but I wasn't sure...

Alternative Future

8:50 am on Dec 15, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You are correct it is possible:

<xsl:element name="img">
<xsl:attribute name="src">
<xsl:text>myimage.jpg</xsl:text>
</xsl:attribute>
<xsl:attribute name='border'>0</xsl:attribute>
</xsl:element>
</xsl:element>

-George

 

Featured Threads

Hot Threads This Week

Hot Threads This Month