homepage Welcome to WebmasterWorld Guest from 54.167.185.110
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / XML Development
Forum Library, Charter, Moderators: httpwebwitch

XML Development Forum

    
Transforming URL in XML data to hyperlink with XSL
mcfly




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

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




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

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




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

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




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

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




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

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

syber




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

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




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

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




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

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

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / XML Development
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved