|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
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
|
|||
|
|||
|
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 |
|
#2
|
|||
|
|||
|
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> |
|
#3
|
|||
|
|||
|
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? |
|
#4
|
|||
|
|||
|
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). |
|
#5
|
|||
|
|||
|
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?? |
|
#6
|
|||
|
|||
|
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.
![]() |
|
#7
|
|||
|
|||
|
You might want to take a look at
URL |
|
#8
|
|||
|
|||
|
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). |
|
#9
|
||||
|
||||
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 |
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > XML Programming > Creating a hyperlink |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|