bookmark - XSL Need Help Translating XML To HTML Hyperlink

XSL Need Help Translating XML To HTML Hyperlink

 
 Discussion by qwijibow with 4 Replies.
 Last Update: March 15, 2005, 4:31 pm
 
bookmark - XSL Need Help Translating XML To HTML Hyperlink  
    
free web hosting
 
Sorry if this sounds stupid, but im new to XML, and i just cant get my head around this problem.

imagine the following XML

CODE

<student name=chris>
 <link>http://.chris.com</link>
<student>



i need to use XSL to translate that to a html hyperlink in the form of

CODE

<a hreh="http://chris.com">chris</a>



at first i tried


CODE

<a href="
<xsl:value-of select="student/link"/>
">
<xsl:value-of select="student/@name"/>
</a>



but that generates a nasty error, obviously because i have embedded tags.

how am i meant to solve this problem ????

i have tried storeing "chris.com" in a xsl variable, but then all i get is a hyperlink to a variable name.

google is clueless, does anyone here have any idea's ??

Wed Mar 9, 2005    Reply    New Discussion   


Sorry about the long wait for a while. I was stomped on this one last night and my connection went off so I couldn't get to do any more testing, but I remembered how to do what you want.

For the sake of completion, here is the XML file I used;

CODE

<?xml version="1.0"?>

<?xml-stylesheet type="text/xsl" href="links.xsl"?>

<students>
[tab][/tab]<student name="Chris">
 <link>http://www.chris.com</link>
[tab][/tab]</student>
[tab][/tab]
[tab][/tab]<student name="Kage">
 <link>http://kage.astahost.com</link>
[tab][/tab]</student>
</students>


So to do what you want, just assign the tag <a> and then use the <xsl:attribute name=" "></xsl: attribute>Text for link here</a>

So the complete code I used is;

CODE

<?xml version="1.0"?>
<xsl:stylesheet version="1.0"                            
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="/">
<html>
<body>
<xsl:for-each select="students/student">
<a><xsl:attribute name="href">
      <xsl:value-of select="link"/></xsl:attribute>
      <xsl:value-of select="@name"/>
      </a>
     <br />
</xsl:for-each>
</body>
</html>
</xsl:template>

</xsl:stylesheet>


Hope this helped. It certainly relit a spark in my head about XML. If you've any qu's in the future on XML, just give me a buzz.

Thu Mar 10, 2005    Reply    New Discussion   

Woops, almost forgot, if you want to see the thing in action, click here example.

Thu Mar 10, 2005    Reply    New Discussion   

Thanks, thats exactly what i needed, i didnt even know htat xsl:attribute existed.

Fri Mar 11, 2005    Reply    New Discussion   


Maybe you should read this?:

http://www.astahost.com/Converting-HTML-ov...XHTML-t501.html

I hope this helpd you.

Tue Mar 15, 2005    Reply    New Discussion   

Quickly Post to XSL Need Help Translating XML To HTML Hyperlink  w/o signup Share Info about XSL Need Help Translating XML To HTML Hyperlink  using Facebook, Twitter etc. email your friend about XSL Need Help Translating XML To HTML Hyperlink Print
Reply / Comment Ask a Question? Share / Bookmark E-Mail a Friend Print

Auto-KeyWord Generating Script.   Auto-KeyWord Generating Script. (5) (6) mIRC Scripting Is there any scripters in here?  mIRC Scripting Is there any scripters in here?