SunQuest
           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:
Get inside! Sample the range of functionality easily built with JMSL Library for Time Series Data Analysis, Heat Maps, Portfolio Optimization, Monte Carlo Simulation, Stock Price Charting and more. Download Now!
  #1  
Old April 11th, 2003, 02:37 PM
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
Question Creating a hyperlink

I'm kind of new to XSLT and I am having trouble figuring out how to create the text for a hyperlink using XSLT and the following XML:

<Record>
<Field name="file" position="1">someFile.html</Field>
<Field name="link" position="2">Click here</Field>
</Record>
... more ...

I would like to use XSLT to build the following HTML from the above data:

<a href=someFile.html>Click here</a>

I have figured out how to build the <a href=...> part and then set the link text to some static value, but I can't seem to figure out how to set the link text to the value from the XML. Here's the relevant piece of my XSLT:

<xsl:for-each select="//Record">
<tr>
<td>
<xsl:for-each select="Field">
<xsl:if test="@position='1'">
<xsl:for-each select="./text()">
<a>
<xsl:attribute name="href">
<xsl:value-of select="."/>
</xsl:attribute>
Static Text</a>
</xsl:for-each>
</xsl:if>
<xsl:if test="@position='2'">
<xsl:for-each select="./text()">
<xsl:value-of select="."/>
</xsl:for-each>
</xsl:if>
</xsl:for-each>
</td>
</tr>
</xsl:for-each>

It creates a hyperlink with the correct href value, but the actual link text is "Static Text" and then it writes out the value of what I want the link text to actually be. I've tried several variations, but I've run out of ideas. Any thoughts?

Thanks
__________________
- MW

Reply With Quote
  #2  
Old April 14th, 2003, 10:23 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
Smile

Well, it may not be the best solution, but I figured out something that works in case anyone is interested:

<xsl:for-each select="//Record">
<tr>
<td>
<xsl:for-each select="Field">
<xsl:if test="@op_position='1'">
<xsl:text disable-output-escaping="yes">
<a href=
</xsl:text>
<xsl:for-each select="./text()">
<xsl:value-of select="."/>
</xsl:for-each>
<xsl:text disable-output-escaping="yes">
>
</xsl:text>
</xsl:if>
<xsl:if test="@op_position='2'">
<xsl:for-each select="./text()">
<xsl:value-of select="."/>
</xsl:for-each>
<xsl:text disable-output-escaping="yes">
</a>
</xsl:text>
</xsl:if>
</xsl:for-each>
</td>
</tr>
</xsl:for-each>

Reply With Quote
  #3  
Old April 15th, 2003, 09:41 AM
go4 go4 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2003
Posts: 8 go4 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
when you do this
<a href=

it'll give you text, not give you hyperlink. Is your work?

Do you guys know any good books,site for xsl?

Reply With Quote
  #4  
Old April 16th, 2003, 08:33 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
Yes this works for me. You have to set the 'disable-output-escaping' attribute to 'yes'. If you don't include this or if you set it to 'no' (the default) you'll just get the text when viewed in a browser and not a hyperlink.

I haven't found any books on XSLT I really like, but there is a tutorial at http://www.w3schools.com that is pretty good. It doesn't go real in depth but it is a good place to start (I think).

Reply With Quote
  #5  
Old May 22nd, 2003, 08:23 AM
alba5 alba5 is offline
Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2002
Posts: 68 alba5 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 35 m
Reputation Power: 7
Surely there is an easier way of doing it instead of using all that code.

Is it possible to refer to a variable not in "tag" form

eg

<variable><xsl: select name = "myVar"/></variable>

and then call the "variable" var directly..$variable, [variable] or something like that??

Reply With Quote
  #6  
Old May 22nd, 2003, 01:51 PM
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 had messed around with doing that, but I couldn't get it to work. Like I said though, mine may not be the best solution.

Reply With Quote
  #7  
Old July 17th, 2003, 03:08 PM
evgruijthuijsen evgruijthuijsen is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Location: The Netherlands
Posts: 2 evgruijthuijsen User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via ICQ to evgruijthuijsen
You might want to take a look at

URL

Reply With Quote
  #8  
Old July 19th, 2003, 05:45 AM
evgruijthuijsen evgruijthuijsen is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Location: The Netherlands
Posts: 2 evgruijthuijsen User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via ICQ to evgruijthuijsen
URL

The text below is taken from the link above:

<!-- Class -->
<xsl:template match="Foundation.Core.Class">
<xsl:variable name="element_name"
select="Foundation.Core.ModelElement.name"/>

<xsl:variable name="xmi_id" select="@xmi.id" />

<div align="center">
<table border="1" width="75%" cellpadding="2" >
<tr>
<td class="class-title" width="20%">Class</td>

<!-- create a hyperlink target for the name -->
<td class="class-name">
<a name="{$element_name}">
<xsl:value-of select="$element_name"/>
</a>
</td>
</tr>



At the beginning of this template a variable, element_name, is declared. The variable is assigned the value of the name of the class by the expression in the select attribute. The purpose for defining a variable is to allow the value of the variable to be substituted by the XSLT processor during a transformation.

This comes into play when defining a hyperlink target for the class definition, using <a name="{$element_name}">. If the XSLT processor didn't provide variable substitution, there would be no way to define the hyperlink target since an XSLT instruction cannot be embedded inside an HTML element (this would violate the XML syntax, from which XSLT is derived).

Reply With Quote
  #9  
Old July 20th, 2003, 08:43 PM
spanglerco's Avatar
spanglerco spanglerco is offline
www.spanglerco.tk
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Location: Georgia
Posts: 36 spanglerco User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
Lightbulb Thanks

This is kind of off topic, but THANKS! I was stuck with my XSL, but your original code suddenly hit me with what I was stuck with.
__________________
Paul Spangler
SpanglerCo
www.spanglerco.tk

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreXML Programming > Creating a hyperlink


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 1 hosted by Hostway