|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
XML+XSL - creating tables with entries being hyperlinks
I am a newbie.
I have built a XML file which is of the format Code:
<tag1>
<tag2>some string 01 </tag2>
<tag2>some string 02 </tag2>
<tag2>some string 03 </tag2>
<tag2>some string 04 </tag2>
</tag1>
I have to create a xsl file to display this. The end result would be a HTML page with a (single column)table of entries from tag2, with each entry being a hyperlink Code:
<tr>
<td width="90%" class="row" ><a class="external" href="#" onClick="sendInfo('some string 01');">some string 01</a></td>
</tr>
which typically calls the sendInfo function in a javascript and sends this value to the parent browser. Coming back to the main question. How do I built an XSL file to do this? Any help would be highly appreciated. Thanks. |
|
#2
|
|||
|
|||
|
Thanks.
I got this working by myself. Had to read a lot though. Moderator please remove this thread. Thanks. |
|
#3
|
||||
|
||||
|
Instead of having a moderator remove the thread (which you could do yourself anyway), post the XSL you came up with so that if others search and run accross your thread, they will have an answer to look at.
__________________
# Jeremy Explain your problem instead of asking how to do what you decided was the solution. |
|
#4
|
|||
|
|||
|
To create links in an XSL template, use xsl:element.
Code:
<xsl:element name = "a"> <xsl:attribute name="href"> <xsl:value-of select="name" /> </xsl:attribute> <xsl:value-of select="name" /> </xsl:element> HTH, /johnny ![]() If you have any questions, post back. |
|
#5
|
||||
|
||||
|
I've found that using brackets is much easier:
Code:
<link url="foo.html" text="foo"> Code:
<xsl:for-each select="link">
<a href="{@url}"><xsl:value-of select="@text" /></a>
</xsl:for-each>
|
|
#6
|
|||
|
|||
|
This worked out fine for me. Sorry for putting the variables specific to my application.
Code:
<xsl:for-each select="medstationlist/medstation">
<tr>
<td class="{$toprowval}"><a href="#" onClick="javascript:sendInfo('{$msName}');"><xsl:value-of select="name"/></a></td>
</tr>
</xsl:for-each>
|
|
#7
|
|||
|
|||
|
I also must admit to being an XML newbie, and I have a similar problem. I have a data file structured like this:
<Site> <URL>yada yada yada</URL> <Name>yada yada yada</Name> <Description>yada yada yada</Description> <Author/> </Site> I'm trying to create a style sheet that will create a a table with two columns. The first column is for name, the second is for description. I need the name to be an active hyperlink with the value of URL. I can't seem to figure a way to merge the two elements. I can create the table fine, just not the combination of data to output that I want. I tried the code in the previous posts with limited success and found nothing in a search of the archives that helped. Any ideas? Thanks in advance Kcmjr |
|
#8
|
||||
|
||||
|
Please post your XSL.
|
|
#9
|
|||
|
|||
|
Hello Kcmjr. Ok, the first problem I see is with your XML code in that it should have a root element. See my example below:
yada.xml Code:
<?xml version="1.0" ?>
<?xml-stylesheet type="text/xsl" href="yada.xsl" ?>
<Pages>
<Site>
<URL>http://yada.com</URL>
<Name>This is the name</Name>
<Description>I am the description yada yada yada</Description>
<Author/>
</Site>
<Site>
<URL>http://yada.com1</URL>
<Name>This is the name1</Name>
<Description>I am the description yada yada yada</Description>
<Author/>
</Site>
<Site>
<URL>http://yada.com2</URL>
<Name>This is the name2</Name>
<Description>I am the description yada yada yada</Description>
<Author/>
</Site>
<Site>
<URL>http://yada.com3</URL>
<Name>This is the name3</Name>
<Description>I am the description yada yada yada</Description>
<Author/>
</Site>
</Pages>
Without seeing your attempt at the XML I can't really offer specific suggestions, but back to the XML, you would want a root element for your document such as "Pages". This way you can cycle through all the "Sites" and display data accordingly. I wrote up an XSL document that I think accomplishes what you were hoping to do: yada.xsl Code:
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<head>
</head>
<body>
<table border="1">
<!-- Label the columns for the Table -->
<thead>
<td>Name</td>
<td>Description</td>
</thead>
<!-- Cycle through all the Sites and display accordingly -->
<xsl:for-each select="Pages/Site">
<tbody>
<td><a href="{URL}"><xsl:value-of select="Name" /></a></td>
<td><xsl:value-of select="Description" /></td>
</tbody>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
Let me know if this solves your problem, or if you have further questions. |
|
#10
|
|||
|
|||
|
tsprings
Good job man! That's a perfect example. Keep it up. |
|
#11
|
|||
|
|||
|
Hello zorrinn. Glad that helped. FYI, I am a woman.
![]() |
|
#12
|
|||
|
|||
|
tsprings
I am sorry. I did not mean that way. The "man" is just another term for giving an "attaboy", atleast that's what I think. Sorry again. |
|
#13
|
|||
|
|||
|
Sorry for the delay in responding everyone, I got REAL busy at work and had a deadline I had to meet.
tsprings, that's just what I was looking for. I adapted my code to what you posted and (after a few failed tries) it works great. Oddly enough I had tried a similar syntax with less than acceptable results. Turns out I had missed a few minor formatting items that you've now edjucated me on. For anyone interested, one of the HTML pages I'm converting can be viewed at http://www.quasatron.com. Click the DOS reference link and the DOS tools link. The XML converted pages should be up in a day or so. Thanks much...... Kcmjr Last edited by Kcmjr : December 11th, 2003 at 02:21 PM. |
|
#14
|
|||
|
|||
|
Hi Kcmjr
I often wonder how this done. When I click on a link on a webpage I noticed that the address in the "address" remains the same. Do you know how to do that? www.xxxxxx.com you click on some link let's say page01.html, but the address still shows as www.xxxxxx.com without the page01.html at the end. |
|
#15
|
|||
|
|||
|
zorrinn,
I'm not entirely sure how its done. My domain name is hosted at one provider and they use something they refer to a "stealth redirection" to redirect content from my Earthlink web page where all my content is located. I expect that at least in this case the servers hosting my URL are retrieving the content and then feeding it back to you themselves. That way the URL appears to allways stay the same when you click on a link. This appears to only work within the same window. If you right click on a link and select "open in new window" the URL in the new window is the true location of the content. Kcmjr |