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 November 10th, 2003, 05:18 PM
zorrinn zorrinn is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2003
Posts: 25 zorrinn User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 15 m 55 sec
Reputation Power: 0
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.

Reply With Quote
  #2  
Old November 12th, 2003, 02:39 PM
zorrinn zorrinn is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2003
Posts: 25 zorrinn User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 15 m 55 sec
Reputation Power: 0
Thanks.

I got this working by myself. Had to read a lot though.

Moderator please remove this thread. Thanks.

Reply With Quote
  #3  
Old November 12th, 2003, 05:12 PM
jharnois's Avatar
jharnois jharnois is offline
mod_dev_shed
Dev Shed God 19th Plane (14000 - 14499 posts)
 
Join Date: Sep 2002
Location: Atlanta, GA
Posts: 14,461 jharnois User rank is Major General (70000 - 90000 Reputation Level)jharnois User rank is Major General (70000 - 90000 Reputation Level)jharnois User rank is Major General (70000 - 90000 Reputation Level)jharnois User rank is Major General (70000 - 90000 Reputation Level)jharnois User rank is Major General (70000 - 90000 Reputation Level)jharnois User rank is Major General (70000 - 90000 Reputation Level)jharnois User rank is Major General (70000 - 90000 Reputation Level)jharnois User rank is Major General (70000 - 90000 Reputation Level)jharnois User rank is Major General (70000 - 90000 Reputation Level)jharnois User rank is Major General (70000 - 90000 Reputation Level)jharnois User rank is Major General (70000 - 90000 Reputation Level)jharnois User rank is Major General (70000 - 90000 Reputation Level)jharnois User rank is Major General (70000 - 90000 Reputation Level)jharnois User rank is Major General (70000 - 90000 Reputation Level) 
Time spent in forums: 1 Month 1 Week 2 Days 15 h 14 m
Reputation Power: 818
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.

Reply With Quote
  #4  
Old November 14th, 2003, 12:30 AM
pezagent pezagent is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Posts: 8 pezagent User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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.

Reply With Quote
  #5  
Old November 14th, 2003, 11:25 AM
jharnois's Avatar
jharnois jharnois is offline
mod_dev_shed
Dev Shed God 19th Plane (14000 - 14499 posts)
 
Join Date: Sep 2002
Location: Atlanta, GA
Posts: 14,461 jharnois User rank is Major General (70000 - 90000 Reputation Level)jharnois User rank is Major General (70000 - 90000 Reputation Level)jharnois User rank is Major General (70000 - 90000 Reputation Level)jharnois User rank is Major General (70000 - 90000 Reputation Level)jharnois User rank is Major General (70000 - 90000 Reputation Level)jharnois User rank is Major General (70000 - 90000 Reputation Level)jharnois User rank is Major General (70000 - 90000 Reputation Level)jharnois User rank is Major General (70000 - 90000 Reputation Level)jharnois User rank is Major General (70000 - 90000 Reputation Level)jharnois User rank is Major General (70000 - 90000 Reputation Level)jharnois User rank is Major General (70000 - 90000 Reputation Level)jharnois User rank is Major General (70000 - 90000 Reputation Level)jharnois User rank is Major General (70000 - 90000 Reputation Level)jharnois User rank is Major General (70000 - 90000 Reputation Level) 
Time spent in forums: 1 Month 1 Week 2 Days 15 h 14 m
Reputation Power: 818
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>

Reply With Quote
  #6  
Old November 14th, 2003, 12:22 PM
zorrinn zorrinn is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2003
Posts: 25 zorrinn User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 15 m 55 sec
Reputation Power: 0
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>

Reply With Quote
  #7  
Old December 4th, 2003, 11:17 AM
Kcmjr Kcmjr is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2003
Location: SF Bay Area
Posts: 5 Kcmjr User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 m 23 sec
Reputation Power: 0
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

Reply With Quote
  #8  
Old December 4th, 2003, 09:10 PM
jharnois's Avatar
jharnois jharnois is offline
mod_dev_shed
Dev Shed God 19th Plane (14000 - 14499 posts)
 
Join Date: Sep 2002
Location: Atlanta, GA
Posts: 14,461 jharnois User rank is Major General (70000 - 90000 Reputation Level)jharnois User rank is Major General (70000 - 90000 Reputation Level)jharnois User rank is Major General (70000 - 90000 Reputation Level)jharnois User rank is Major General (70000 - 90000 Reputation Level)jharnois User rank is Major General (70000 - 90000 Reputation Level)jharnois User rank is Major General (70000 - 90000 Reputation Level)jharnois User rank is Major General (70000 - 90000 Reputation Level)jharnois User rank is Major General (70000 - 90000 Reputation Level)jharnois User rank is Major General (70000 - 90000 Reputation Level)jharnois User rank is Major General (70000 - 90000 Reputation Level)jharnois User rank is Major General (70000 - 90000 Reputation Level)jharnois User rank is Major General (70000 - 90000 Reputation Level)jharnois User rank is Major General (70000 - 90000 Reputation Level)jharnois User rank is Major General (70000 - 90000 Reputation Level) 
Time spent in forums: 1 Month 1 Week 2 Days 15 h 14 m
Reputation Power: 818
Please post your XSL.

Reply With Quote
  #9  
Old December 5th, 2003, 02:28 PM
tsprings tsprings is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2003
Location: Seattle, WA
Posts: 55 tsprings User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 m 20 sec
Reputation Power: 5
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.

Reply With Quote
  #10  
Old December 5th, 2003, 04:38 PM
zorrinn zorrinn is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2003
Posts: 25 zorrinn User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 15 m 55 sec
Reputation Power: 0
tsprings

Good job man! That's a perfect example. Keep it up.

Reply With Quote
  #11  
Old December 5th, 2003, 04:41 PM
tsprings tsprings is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2003
Location: Seattle, WA
Posts: 55 tsprings User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 m 20 sec
Reputation Power: 5
Hello zorrinn. Glad that helped. FYI, I am a woman.

Reply With Quote
  #12  
Old December 6th, 2003, 08:37 AM
zorrinn zorrinn is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2003
Posts: 25 zorrinn User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 15 m 55 sec
Reputation Power: 0
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.

Reply With Quote
  #13  
Old December 11th, 2003, 01:05 PM
Kcmjr Kcmjr is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2003
Location: SF Bay Area
Posts: 5 Kcmjr User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 m 23 sec
Reputation Power: 0
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.

Reply With Quote
  #14  
Old December 11th, 2003, 03:05 PM
zorrinn zorrinn is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2003
Posts: 25 zorrinn User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 15 m 55 sec
Reputation Power: 0
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.

Reply With Quote
  #15  
Old December 11th, 2003, 03:19 PM
Kcmjr Kcmjr is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2003
Location: SF Bay Area
Posts: 5 Kcmjr User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 m 23 sec
Reputation Power: 0
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

Reply With Quote