SunQuest
           XML Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Try It Free
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:
Stop making mediocre tutorials.The best tutorials are video! Camtasia Studio makes it easy to create engaging, buzz-building screen videos at any size, in any popular format. Download the free trial!
  #1  
Old April 16th, 2003, 06:44 PM
jeofoyster jeofoyster is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2001
Location: L.A.
Posts: 4 jeofoyster User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Question getting attribute from element with XSL

Hi -
Let's say i have this XML:

<content>
<para>bla bla bla bla bla bla <link url="http://jeof.net">link name</link> bla bla bla</para>

<para>yada yada yada</para>
</content>

Now - I want to create a anchor/link inside the body of the paragraph using the URL in the attribute - but how do I get the value of the attribute??

Here's one thing I've done:


<xsl:template match="content">
<xsl:for-each select="p">
<p><xsl:apply-templates /></p>
</xsl:for-each>
</xsl:template>

<xsl:template match="p//link">
<a href="">
<xsl:value-of select="."/>
</a>
</xsl:template>

And it generates the paragraph just fine - but I need to get the value of the url attribute from the <link> element in my XML into the href attribute of the outputted HTML.

How?

thanks

Reply With Quote
  #2  
Old April 17th, 2003, 11:47 AM
waldthau waldthau is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2001
Location: Colorado
Posts: 46 waldthau User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 8
I think this will do what you want:

Code:
<xsl:template match="content">
	<xsl:for-each select="p"> 
		<p><xsl:apply-templates /></p> 
	</xsl:for-each> 
</xsl:template>

<xsl:template match="p//link">
	<a>
	<xsl:attribute name="href">
		<xsl:value-of select="@url"/>
	</xsl:attribute>
	<xsl:value-of select="."/>
	</a>
</xsl:template>

Hope that helps!
__________________
- MW

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreXML Programming > getting attribute from element with XSL


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