XML Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreXML Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old September 28th, 2004, 09:38 AM
jarnold jarnold is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2004
Posts: 1 jarnold User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
XSL: In-Line Links

I am having trouble finding a way to transform links from XML data into HTML links - and have them appear at the appropriate place in the text.

Consider the following XML data source.

<p>This webpage can be found
<link url=“http:www.somewhere.com”>here</link>
on the web.</p>

Now, I have had no trouble grabbing the text of the paragraph for HTML using this XSL:

<xsl:for-each select="//p">
<p><xsl:value-of select="."/></p>
</xsl:for-each>

But, unfortunately that only prints the text and does not create a link.

(i.e. HTML result is <p>This webpage can be found here on the web.</p>)

I can transform the link data to an HTML link using this XSL:

<xsl:for-each select="//link">
<xsl:element name="a">
<xsl:attribute name="href">
<xsl:value-of select="//link/@url" />
</xsl:attribute>
<xsl:attribute name="target">blank</xsl:attribute>
<xsl:value-of select="//link" />
</xsl:element>
</xsl:for-each>

But, unfortunately that only prints the link and not the surrounding paragraph.

(i.e. HTML result is <a href=“http://www.somewhere.com” target=“blank”>here</a>)


My problem is that I would like to transform the link and print the paragraph with the link in it.

i.e. I would like for the HTML to be:

<p> This webpage can be found <a href=“http:www.somewhere.com” target=”blank>here</a> on the web</p>



Can anyone help me with this?

Reply With Quote
  #2  
Old October 4th, 2004, 04:56 AM
Miska's Avatar
Miska Miska is offline
Madden Maniac
Dev Shed Novice (500 - 999 posts)
 
Join Date: Jun 2001
Location: Finland
Posts: 519 Miska User rank is Lance Corporal (50 - 100 Reputation Level)Miska User rank is Lance Corporal (50 - 100 Reputation Level)Miska User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 1 Day 3 h 47 m 50 sec
Reputation Power: 8
Hope you have this figured out already... If not here's simple solution for you:

Code:
<?xml version="1.0" encoding="iso-8859-1" ?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.1">
<xsl:template match="p">
<html>
<body>
<p>
<xsl:value-of select="substring-before(//p,'here')"/>
<xsl:for-each select="//link">
<xsl:element name="a">
<xsl:attribute name="href">
<xsl:value-of select="//link/@url" />
</xsl:attribute>
<xsl:attribute name="target">blank</xsl:attribute>
<xsl:value-of select="//link" />
</xsl:element>
</xsl:for-each>
<xsl:value-of select="substring-after(//p,'here')"/>
</p>
</body>
</html>
</xsl:template>
</xsl:stylesheet>

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreXML Programming > XSL: In-Line Links


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway
Stay green...Green IT